Skip to content

Commit 457db29

Browse files
wangbaolin719johnstultz-work
authored andcommitted
security: Introduce security_settime64()
security_settime() uses a timespec, which is not year 2038 safe on 32bit systems. Thus this patch introduces the security_settime64() function with timespec64 type. We also convert the cap_settime() helper function to use the 64bit types. This patch then moves security_settime() to the header file as an inline helper function so that existing users can be iteratively converted. None of the existing hooks is using the timespec argument and therefor the patch is not making any functional changes. Cc: Serge Hallyn <[email protected]>, Cc: James Morris <[email protected]>, Cc: "Serge E. Hallyn" <[email protected]>, Cc: Paul Moore <[email protected]> Cc: Stephen Smalley <[email protected]> Cc: Kees Cook <[email protected]> Cc: Prarit Bhargava <[email protected]> Cc: Richard Cochran <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Ingo Molnar <[email protected]> Reviewed-by: James Morris <[email protected]> Signed-off-by: Baolin Wang <[email protected]> [jstultz: Reworded commit message] Signed-off-by: John Stultz <[email protected]>
1 parent 02fad5e commit 457db29

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

include/linux/lsm_hooks.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,8 @@
11901190
* Return 0 if permission is granted.
11911191
* @settime:
11921192
* Check permission to change the system time.
1193-
* struct timespec and timezone are defined in include/linux/time.h
1193+
* struct timespec64 is defined in include/linux/time64.h and timezone
1194+
* is defined in include/linux/time.h
11941195
* @ts contains new time
11951196
* @tz contains new timezone
11961197
* Return 0 if permission is granted.
@@ -1327,7 +1328,7 @@ union security_list_options {
13271328
int (*quotactl)(int cmds, int type, int id, struct super_block *sb);
13281329
int (*quota_on)(struct dentry *dentry);
13291330
int (*syslog)(int type);
1330-
int (*settime)(const struct timespec *ts, const struct timezone *tz);
1331+
int (*settime)(const struct timespec64 *ts, const struct timezone *tz);
13311332
int (*vm_enough_memory)(struct mm_struct *mm, long pages);
13321333

13331334
int (*bprm_set_creds)(struct linux_binprm *bprm);

include/linux/security.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct timezone;
7171
/* These functions are in security/commoncap.c */
7272
extern int cap_capable(const struct cred *cred, struct user_namespace *ns,
7373
int cap, int audit);
74-
extern int cap_settime(const struct timespec *ts, const struct timezone *tz);
74+
extern int cap_settime(const struct timespec64 *ts, const struct timezone *tz);
7575
extern int cap_ptrace_access_check(struct task_struct *child, unsigned int mode);
7676
extern int cap_ptrace_traceme(struct task_struct *parent);
7777
extern int cap_capget(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
@@ -208,7 +208,13 @@ int security_capable_noaudit(const struct cred *cred, struct user_namespace *ns,
208208
int security_quotactl(int cmds, int type, int id, struct super_block *sb);
209209
int security_quota_on(struct dentry *dentry);
210210
int security_syslog(int type);
211-
int security_settime(const struct timespec *ts, const struct timezone *tz);
211+
int security_settime64(const struct timespec64 *ts, const struct timezone *tz);
212+
static inline int security_settime(const struct timespec *ts, const struct timezone *tz)
213+
{
214+
struct timespec64 ts64 = timespec_to_timespec64(*ts);
215+
216+
return security_settime64(&ts64, tz);
217+
}
212218
int security_vm_enough_memory_mm(struct mm_struct *mm, long pages);
213219
int security_bprm_set_creds(struct linux_binprm *bprm);
214220
int security_bprm_check(struct linux_binprm *bprm);
@@ -462,10 +468,18 @@ static inline int security_syslog(int type)
462468
return 0;
463469
}
464470

471+
static inline int security_settime64(const struct timespec64 *ts,
472+
const struct timezone *tz)
473+
{
474+
return cap_settime(ts, tz);
475+
}
476+
465477
static inline int security_settime(const struct timespec *ts,
466478
const struct timezone *tz)
467479
{
468-
return cap_settime(ts, tz);
480+
struct timespec64 ts64 = timespec_to_timespec64(*ts);
481+
482+
return cap_settime(&ts64, tz);
469483
}
470484

471485
static inline int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)

security/commoncap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
111111
* Determine whether the current process may set the system clock and timezone
112112
* information, returning 0 if permission granted, -ve if denied.
113113
*/
114-
int cap_settime(const struct timespec *ts, const struct timezone *tz)
114+
int cap_settime(const struct timespec64 *ts, const struct timezone *tz)
115115
{
116116
if (!capable(CAP_SYS_TIME))
117117
return -EPERM;

security/security.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ int security_syslog(int type)
208208
return call_int_hook(syslog, 0, type);
209209
}
210210

211-
int security_settime(const struct timespec *ts, const struct timezone *tz)
211+
int security_settime64(const struct timespec64 *ts, const struct timezone *tz)
212212
{
213213
return call_int_hook(settime, 0, ts, tz);
214214
}

0 commit comments

Comments
 (0)