aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBaolin Wang <baolin.wang@linaro.org>2016-04-08 02:02:11 -0400
committerJohn Stultz <john.stultz@linaro.org>2016-04-22 14:48:30 -0400
commit457db29bfcfd1d9cc717587c446a89d60499d4a9 (patch)
tree2416285b5a4c69e386e136df9e649825c5fab6fd
parent02fad5e9b433da3829d39f0afb3c51b4b6409ed5 (diff)
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 <serge.hallyn@canonical.com>, Cc: James Morris <james.l.morris@oracle.com>, Cc: "Serge E. Hallyn" <serge@hallyn.com>, Cc: Paul Moore <pmoore@redhat.com> Cc: Stephen Smalley <sds@tycho.nsa.gov> Cc: Kees Cook <keescook@chromium.org> Cc: Prarit Bhargava <prarit@redhat.com> Cc: Richard Cochran <richardcochran@gmail.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@kernel.org> Reviewed-by: James Morris <james.l.morris@oracle.com> Signed-off-by: Baolin Wang <baolin.wang@linaro.org> [jstultz: Reworded commit message] Signed-off-by: John Stultz <john.stultz@linaro.org>
-rw-r--r--include/linux/lsm_hooks.h5
-rw-r--r--include/linux/security.h20
-rw-r--r--security/commoncap.c2
-rw-r--r--security/security.c2
4 files changed, 22 insertions, 7 deletions
diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h
index cdee11cbcdf1..41ab4662f95c 100644
--- a/include/linux/lsm_hooks.h
+++ b/include/linux/lsm_hooks.h
@@ -1190,7 +1190,8 @@
1190 * Return 0 if permission is granted. 1190 * Return 0 if permission is granted.
1191 * @settime: 1191 * @settime:
1192 * Check permission to change the system time. 1192 * 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
1194 * @ts contains new time 1195 * @ts contains new time
1195 * @tz contains new timezone 1196 * @tz contains new timezone
1196 * Return 0 if permission is granted. 1197 * Return 0 if permission is granted.
@@ -1327,7 +1328,7 @@ union security_list_options {
1327 int (*quotactl)(int cmds, int type, int id, struct super_block *sb); 1328 int (*quotactl)(int cmds, int type, int id, struct super_block *sb);
1328 int (*quota_on)(struct dentry *dentry); 1329 int (*quota_on)(struct dentry *dentry);
1329 int (*syslog)(int type); 1330 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);
1331 int (*vm_enough_memory)(struct mm_struct *mm, long pages); 1332 int (*vm_enough_memory)(struct mm_struct *mm, long pages);
1332 1333
1333 int (*bprm_set_creds)(struct linux_binprm *bprm); 1334 int (*bprm_set_creds)(struct linux_binprm *bprm);
diff --git a/include/linux/security.h b/include/linux/security.h
index 157f0cb1e4d2..35ac8d9d4739 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -71,7 +71,7 @@ struct timezone;
71/* These functions are in security/commoncap.c */ 71/* These functions are in security/commoncap.c */
72extern int cap_capable(const struct cred *cred, struct user_namespace *ns, 72extern int cap_capable(const struct cred *cred, struct user_namespace *ns,
73 int cap, int audit); 73 int cap, int audit);
74extern int cap_settime(const struct timespec *ts, const struct timezone *tz); 74extern int cap_settime(const struct timespec64 *ts, const struct timezone *tz);
75extern int cap_ptrace_access_check(struct task_struct *child, unsigned int mode); 75extern int cap_ptrace_access_check(struct task_struct *child, unsigned int mode);
76extern int cap_ptrace_traceme(struct task_struct *parent); 76extern int cap_ptrace_traceme(struct task_struct *parent);
77extern int cap_capget(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted); 77extern 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,
208int security_quotactl(int cmds, int type, int id, struct super_block *sb); 208int security_quotactl(int cmds, int type, int id, struct super_block *sb);
209int security_quota_on(struct dentry *dentry); 209int security_quota_on(struct dentry *dentry);
210int security_syslog(int type); 210int security_syslog(int type);
211int security_settime(const struct timespec *ts, const struct timezone *tz); 211int security_settime64(const struct timespec64 *ts, const struct timezone *tz);
212static 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}
212int security_vm_enough_memory_mm(struct mm_struct *mm, long pages); 218int security_vm_enough_memory_mm(struct mm_struct *mm, long pages);
213int security_bprm_set_creds(struct linux_binprm *bprm); 219int security_bprm_set_creds(struct linux_binprm *bprm);
214int security_bprm_check(struct linux_binprm *bprm); 220int security_bprm_check(struct linux_binprm *bprm);
@@ -462,10 +468,18 @@ static inline int security_syslog(int type)
462 return 0; 468 return 0;
463} 469}
464 470
471static inline int security_settime64(const struct timespec64 *ts,
472 const struct timezone *tz)
473{
474 return cap_settime(ts, tz);
475}
476
465static inline int security_settime(const struct timespec *ts, 477static inline int security_settime(const struct timespec *ts,
466 const struct timezone *tz) 478 const struct timezone *tz)
467{ 479{
468 return cap_settime(ts, tz); 480 struct timespec64 ts64 = timespec_to_timespec64(*ts);
481
482 return cap_settime(&ts64, tz);
469} 483}
470 484
471static inline int security_vm_enough_memory_mm(struct mm_struct *mm, long pages) 485static inline int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
diff --git a/security/commoncap.c b/security/commoncap.c
index 48071ed7c445..2074bf6a2fe3 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -111,7 +111,7 @@ int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
111 * Determine whether the current process may set the system clock and timezone 111 * Determine whether the current process may set the system clock and timezone
112 * information, returning 0 if permission granted, -ve if denied. 112 * information, returning 0 if permission granted, -ve if denied.
113 */ 113 */
114int cap_settime(const struct timespec *ts, const struct timezone *tz) 114int cap_settime(const struct timespec64 *ts, const struct timezone *tz)
115{ 115{
116 if (!capable(CAP_SYS_TIME)) 116 if (!capable(CAP_SYS_TIME))
117 return -EPERM; 117 return -EPERM;
diff --git a/security/security.c b/security/security.c
index 3644b0344d29..8c44a64f191d 100644
--- a/security/security.c
+++ b/security/security.c
@@ -208,7 +208,7 @@ int security_syslog(int type)
208 return call_int_hook(syslog, 0, type); 208 return call_int_hook(syslog, 0, type);
209} 209}
210 210
211int security_settime(const struct timespec *ts, const struct timezone *tz) 211int security_settime64(const struct timespec64 *ts, const struct timezone *tz)
212{ 212{
213 return call_int_hook(settime, 0, ts, tz); 213 return call_int_hook(settime, 0, ts, tz);
214} 214}