Make ipc y2038 safe
Subsystems (3)
v2 cover Make ipc y2038 safe
The series aims to transition internal workings of ipc subsystem to use y2038-safe types and apis.
The series is based on Al Viro's #work.ipc branch.
Changes since v1:
* Addressed audit review comments
Deepa Dinamani (6):
ipc: Make sys_semtimedop() y2038 safe
ipc: mqueue: Replace timespec with timespec64
ipc: msg: Make msg_queue timestamps y2038 safe
ipc: sem: Make sem_array timestamps y2038 safe
ipc: shm: Make shmid_kernel timestamps y2038 safe
utimes: Make utimes y2038 safe
fs/utimes.c | 23 ++++++++++++----------- include/linux/audit.h | 6 +++--- include/linux/msg.h | 7 ++++--- include/linux/sem.h | 3 ++- include/linux/shm.h | 6 +++--- include/linux/time.h | 2 +- init/initramfs.c | 2 +- ipc/mqueue.c | 28 ++++++++++++++-------------- ipc/msg.c | 12 ++++++------ ipc/sem.c | 34 +++++++++++++++++----------------- ipc/shm.c | 16 ++++++++-------- kernel/audit.h | 2 +- kernel/auditsc.c | 12 ++++++------ 13 files changed, 78 insertions(+), 75 deletions(-)
Signature · 1 line
2.11.0
PATCH v2 1/6 ipc: Make sys_semtimedop() y2038 safe
struct timespec is not y2038 safe on 32 bit machines. Replace timespec with y2038 safe struct timespec64.
Note that the patch only changes the internals without modifying the syscall interface. This will be part of a separate series.
--- ipc/sem.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
ipc/sem.c +6 -6
@@ -1861,7 +1861,7 @@ static struct sem_undo *find_alloc_undo(struct ipc_namespace *ns, int semid) }static long do_semtimedop (int semid,struct sembuf __user *tsops, -unsigned nsops,const struct timespec *timeout) +unsigned nsops,const struct timespec64 *timeout) {int error = -EINVAL ;struct sem_array *sma;
@@ -1897,7 +1897,7 @@ static long do_semtimedop(int semid, struct sembuf __user *tsops, error = -EINVAL ; goto out_free; } - jiffies_left =timespec_to_jiffies (timeout); + jiffies_left =timespec64_to_jiffies (timeout); } max =0 ;
@@ -2116,8 +2116,8 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops, unsigned, nsops, const struct timespec __user *, timeout) { if (timeout) { - struct timespec ts; -if (copy_from_user (&ts, timeout,sizeof (*timeout))) + struct timespec64 ts; +if (get_timespec64 (&ts, timeout))return -EFAULT ;return do_semtimedop (semid, tsops, nsops, &ts); }
@@ -2130,8 +2130,8 @@ COMPAT_SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsems, const struct compat_timespec __user *, timeout) {if (timeout) { -struct timespec ts; -if (compat_get_timespec (&ts, timeout)) +struct timespec64 ts; +if (compat_get_timespec64 (&ts, timeout))return -EFAULT ;return do_semtimedop (semid, tsems, nsops, &ts); }
Signature · 1 line
2.11.0
PATCH v2 2/6 ipc: mqueue: Replace timespec with timespec64
In reply to Deepa Dinamanistruct timespec is not y2038 safe. Replace all uses of timespec by y2038 safe struct timespec64.
Even though timespec is used here to represent timeouts, replace these with timespec64 so that it facilitates in verification by creating a y2038 safe kernel image that is free of timespec.
The syscall interfaces themselves are not changed as part of the patch. They will be part of a different series.
--- include/linux/audit.h | 6 +++--- ipc/mqueue.c | 28 ++++++++++++++-------------- kernel/audit.h | 2 +- kernel/auditsc.c | 12 ++++++------ 4 files changed, 24 insertions(+), 24 deletions(-)
include/linux/audit.h +3 -3
@@ -351,7 +351,7 @@ extern int __audit_socketcall(int nargs, unsigned long *args);extern int __audit_sockaddr (int len,void *addr);extern void __audit_fd_pair (int fd1,int fd2);extern void __audit_mq_open (int oflag,umode_t mode,struct mq_attr *attr); -extern void __audit_mq_sendrecv (mqd_t mqdes,size_t msg_len,unsigned int msg_prio,const struct timespec *abs_timeout); +extern void __audit_mq_sendrecv (mqd_t mqdes,size_t msg_len,unsigned int msg_prio,const struct timespec64 *abs_timeout);extern void __audit_mq_notify (mqd_t mqdes,const struct sigevent *notification);extern void __audit_mq_getsetattr (mqd_t mqdes,struct mq_attr *mqstat); extern int __audit_log_bprm_fcaps(struct linux_binprm *bprm,
@@ -412,7 +412,7 @@ static inline void audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr)if (unlikely (!audit_dummy_context ()))__audit_mq_open (oflag, mode, attr); } -static inline void audit_mq_sendrecv (mqd_t mqdes,size_t msg_len,unsigned int msg_prio,const struct timespec *abs_timeout) +static inline void audit_mq_sendrecv (mqd_t mqdes,size_t msg_len,unsigned int msg_prio,const struct timespec64 *abs_timeout) {if (unlikely (!audit_dummy_context ()))__audit_mq_sendrecv (mqdes, msg_len, msg_prio, abs_timeout);
@@ -549,7 +549,7 @@ static inline void audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr) { }static inline void audit_mq_sendrecv (mqd_t mqdes,size_t msg_len,unsigned int msg_prio, -const struct timespec *abs_timeout) +const struct timespec64 *abs_timeout) { }static inline void audit_mq_notify (mqd_t mqdes,const struct sigevent *notification)
ipc/mqueue.c +14 -14
@@ -668,11 +668,11 @@ static void __do_notify(struct mqueue_inode_info *info) }static int prepare_timeout (const struct timespec __user *u_abs_timeout, -struct timespec *ts) +struct timespec64 *ts) { -if (copy_from_user (ts, u_abs_timeout,sizeof (struct timespec ))) +if (get_timespec64 (ts, u_abs_timeout))return -EFAULT ; -if (!timespec_valid (ts)) +if (!timespec64_valid (ts))return -EINVAL ;return 0 ; }
@@ -962,7 +962,7 @@ static inline void pipelined_receive(struct wake_q_head *wake_q,static int do_mq_timedsend (mqd_t mqdes,const char __user *u_msg_ptr,size_t msg_len,unsigned int msg_prio, -struct timespec *ts) +struct timespec64 *ts) {struct fd f;struct inode *inode;
@@ -979,7 +979,7 @@ static int do_mq_timedsend(mqd_t mqdes, const char __user *u_msg_ptr,return -EINVAL ;if (ts) { - expires =timespec_to_ktime (*ts); + expires =timespec64_to_ktime (*ts); timeout = &expires; }
@@ -1080,7 +1080,7 @@ static int do_mq_timedsend(mqd_t mqdes, const char __user *u_msg_ptr,static int do_mq_timedreceive (mqd_t mqdes,char __user *u_msg_ptr,size_t msg_len,unsigned int __user *u_msg_prio, -struct timespec *ts) +struct timespec64 *ts) {ssize_t ret;struct msg_msg *msg_ptr;
@@ -1092,7 +1092,7 @@ static int do_mq_timedreceive(mqd_t mqdes, char __user *u_msg_ptr,struct posix_msg_tree_node *new_leaf =NULL ;if (ts) { - expires =timespec_to_ktime (*ts); + expires =timespec64_to_ktime (*ts); timeout = &expires; }
@@ -1184,7 +1184,7 @@ SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes, const char __user *, u_msg_ptr, size_t, msg_len, unsigned int, msg_prio, const struct timespec __user *, u_abs_timeout) { - struct timespec ts, *p = NULL; + struct timespec64 ts, *p = NULL;if (u_abs_timeout) {int res =prepare_timeout (u_abs_timeout, &ts);if (res)
@@ -1198,7 +1198,7 @@ SYSCALL_DEFINE5(mq_timedreceive, mqd_t, mqdes, char __user *, u_msg_ptr, size_t, msg_len, unsigned int __user *, u_msg_prio, const struct timespec __user *, u_abs_timeout) { - struct timespec ts, *p = NULL; + struct timespec64 ts, *p = NULL;if (u_abs_timeout) {int res =prepare_timeout (u_abs_timeout, &ts);if (res)
@@ -1473,11 +1473,11 @@ COMPAT_SYSCALL_DEFINE4(mq_open, const char __user *, u_name, }static int compat_prepare_timeout (const struct compat_timespec __user *p, -struct timespec *ts) +struct timespec64 *ts) { -if (compat_get_timespec (ts, p)) +if (compat_get_timespec64 (ts, p))return -EFAULT ; -if (!timespec_valid (ts)) +if (!timespec64_valid (ts))return -EINVAL ;return 0 ; }
@@ -1487,7 +1487,7 @@ COMPAT_SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes, compat_size_t, msg_len, unsigned int, msg_prio, const struct compat_timespec __user *, u_abs_timeout) { -struct timespec ts, *p =NULL ; +struct timespec64 ts, *p =NULL ;if (u_abs_timeout) {int res =compat_prepare_timeout (u_abs_timeout, &ts);if (res)
@@ -1502,7 +1502,7 @@ COMPAT_SYSCALL_DEFINE5(mq_timedreceive, mqd_t, mqdes, compat_size_t, msg_len, unsigned int __user *, u_msg_prio, const struct compat_timespec __user *, u_abs_timeout) { -struct timespec ts, *p =NULL ; +struct timespec64 ts, *p =NULL ;if (u_abs_timeout) {int res =compat_prepare_timeout (u_abs_timeout, &ts);if (res)
kernel/audit.h +1 -1
@@ -182,7 +182,7 @@ struct audit_context {mqd_t mqdes;size_t msg_len;unsigned int msg_prio; -struct timespec abs_timeout; +struct timespec64 abs_timeout; } mq_sendrecv;struct {int oflag;
kernel/auditsc.c +6 -6
@@ -1235,11 +1235,11 @@ static void show_special(struct audit_context *context, int *call_panic)case AUDIT_MQ_SENDRECV :audit_log_format (ab,"mqdes=%d msg_len=%zd msg_prio=%u " -"abs_timeout_sec=%ld abs_timeout_nsec=%ld" , +"abs_timeout_sec=%lld abs_timeout_nsec=%ld" , context->mq_sendrecv.mqdes, context->mq_sendrecv.msg_len, context->mq_sendrecv.msg_prio, - context->mq_sendrecv.abs_timeout.tv_sec, + (long long ) context->mq_sendrecv.abs_timeout.tv_sec, context->mq_sendrecv.abs_timeout.tv_nsec);break ;case AUDIT_MQ_NOTIFY :
@@ -2083,15 +2083,15 @@ void __audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr)* */ void __audit_mq_sendrecv (mqd_t mqdes,size_t msg_len,unsigned int msg_prio, -const struct timespec *abs_timeout) +const struct timespec64 *abs_timeout) {struct audit_context *context = current->audit_context; -struct timespec *p = &context->mq_sendrecv.abs_timeout; +struct timespec64 *p = &context->mq_sendrecv.abs_timeout;if (abs_timeout) -memcpy (p, abs_timeout,sizeof (struct timespec )); +memcpy (p, abs_timeout,sizeof (*p));else -memset (p,0 ,sizeof (struct timespec )); +memset (p,0 ,sizeof (*p)); context->mq_sendrecv.mqdes = mqdes; context->mq_sendrecv.msg_len = msg_len;
Signature · 1 line
2.11.0
Re: [PATCH v2 2/6] ipc: mqueue: Replace timespec with timespec64
Quoted 15 lines · Deepa Dinamani
struct timespec is not y2038 safe. Replace all uses of timespec by y2038 safe struct timespec64.
Even though timespec is used here to represent timeouts, replace these with timespec64 so that it facilitates in verification by creating a y2038 safe kernel image that is free of timespec.
The syscall interfaces themselves are not changed as part of the patch. They will be part of a different series.
Signed-off-by Deepa Dinamani <[email protected]>Cc Paul Moore <[email protected]>Cc Richard Guy Briggs <[email protected]>Reviewed-by Richard Guy Briggs <[email protected]>
Quoted 6 lines
--- include/linux/audit.h | 6 +++--- ipc/mqueue.c | 28 ++++++++++++++-------------- kernel/audit.h | 2 +- kernel/auditsc.c | 12 ++++++------ 4 files changed, 24 insertions(+), 24 deletions(-)
The audit bits look fine. Deepa, I assume you are going to seek to have this go in through a tree other than audit?
Quoted 191 lines
include/linux/audit.h +3
-3@@ -351,7 +351,7 @@ extern int __audit_socketcall(int nargs, unsigned long *args);extern int __audit_sockaddr (int len,void *addr);extern void __audit_fd_pair (int fd1,int fd2);extern void __audit_mq_open (int oflag,umode_t mode,struct mq_attr *attr); -extern void __audit_mq_sendrecv (mqd_t mqdes,size_t msg_len,unsigned int msg_prio,const struct timespec *abs_timeout); +extern void __audit_mq_sendrecv (mqd_t mqdes,size_t msg_len,unsigned int msg_prio,const struct timespec64 *abs_timeout);extern void __audit_mq_notify (mqd_t mqdes,const struct sigevent *notification);extern void __audit_mq_getsetattr (mqd_t mqdes,struct mq_attr *mqstat); extern int __audit_log_bprm_fcaps(struct linux_binprm *bprm,@@ -412,7 +412,7 @@ static inline void audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr)if (unlikely (!audit_dummy_context ()))__audit_mq_open (oflag, mode, attr); } -static inline void audit_mq_sendrecv (mqd_t mqdes,size_t msg_len,unsigned int msg_prio,const struct timespec *abs_timeout) +static inline void audit_mq_sendrecv (mqd_t mqdes,size_t msg_len,unsigned int msg_prio,const struct timespec64 *abs_timeout) {if (unlikely (!audit_dummy_context ()))__audit_mq_sendrecv (mqdes, msg_len, msg_prio, abs_timeout);@@ -549,7 +549,7 @@ static inline void audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr) { }static inline void audit_mq_sendrecv (mqd_t mqdes,size_t msg_len,unsigned int msg_prio, -const struct timespec *abs_timeout) +const struct timespec64 *abs_timeout) { }static inline void audit_mq_notify (mqd_t mqdes,const struct sigevent *notification)ipc/mqueue.c +14
-14@@ -668,11 +668,11 @@ static void __do_notify(struct mqueue_inode_info *info) }static int prepare_timeout (const struct timespec __user *u_abs_timeout, -struct timespec *ts) +struct timespec64 *ts) { -if (copy_from_user (ts, u_abs_timeout,sizeof (struct timespec ))) +if (get_timespec64 (ts, u_abs_timeout))return -EFAULT ; -if (!timespec_valid (ts)) +if (!timespec64_valid (ts))return -EINVAL ;return 0 ; }@@ -962,7 +962,7 @@ static inline void pipelined_receive(struct wake_q_head *wake_q,static int do_mq_timedsend (mqd_t mqdes,const char __user *u_msg_ptr,size_t msg_len,unsigned int msg_prio, -struct timespec *ts) +struct timespec64 *ts) {struct fd f;struct inode *inode;@@ -979,7 +979,7 @@ static int do_mq_timedsend(mqd_t mqdes, const char __user *u_msg_ptr,return -EINVAL ;if (ts) { - expires =timespec_to_ktime (*ts); + expires =timespec64_to_ktime (*ts); timeout = &expires; }@@ -1080,7 +1080,7 @@ static int do_mq_timedsend(mqd_t mqdes, const char __user *u_msg_ptr,static int do_mq_timedreceive (mqd_t mqdes,char __user *u_msg_ptr,size_t msg_len,unsigned int __user *u_msg_prio, -struct timespec *ts) +struct timespec64 *ts) {ssize_t ret;struct msg_msg *msg_ptr;@@ -1092,7 +1092,7 @@ static int do_mq_timedreceive(mqd_t mqdes, char __user *u_msg_ptr,struct posix_msg_tree_node *new_leaf =NULL ;if (ts) { - expires =timespec_to_ktime (*ts); + expires =timespec64_to_ktime (*ts); timeout = &expires; }@@ -1184,7 +1184,7 @@ SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes, const char __user *, u_msg_ptr, size_t, msg_len, unsigned int, msg_prio, const struct timespec __user *, u_abs_timeout) { - struct timespec ts, *p = NULL; + struct timespec64 ts, *p = NULL;if (u_abs_timeout) {int res =prepare_timeout (u_abs_timeout, &ts);if (res)@@ -1198,7 +1198,7 @@ SYSCALL_DEFINE5(mq_timedreceive, mqd_t, mqdes, char __user *, u_msg_ptr, size_t, msg_len, unsigned int __user *, u_msg_prio, const struct timespec __user *, u_abs_timeout) { - struct timespec ts, *p = NULL; + struct timespec64 ts, *p = NULL;if (u_abs_timeout) {int res =prepare_timeout (u_abs_timeout, &ts);if (res)@@ -1473,11 +1473,11 @@ COMPAT_SYSCALL_DEFINE4(mq_open, const char __user *, u_name, }static int compat_prepare_timeout (const struct compat_timespec __user *p, -struct timespec *ts) +struct timespec64 *ts) { -if (compat_get_timespec (ts, p)) +if (compat_get_timespec64 (ts, p))return -EFAULT ; -if (!timespec_valid (ts)) +if (!timespec64_valid (ts))return -EINVAL ;return 0 ; }@@ -1487,7 +1487,7 @@ COMPAT_SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes, compat_size_t, msg_len, unsigned int, msg_prio, const struct compat_timespec __user *, u_abs_timeout) { -struct timespec ts, *p =NULL ; +struct timespec64 ts, *p =NULL ;if (u_abs_timeout) {int res =compat_prepare_timeout (u_abs_timeout, &ts);if (res)@@ -1502,7 +1502,7 @@ COMPAT_SYSCALL_DEFINE5(mq_timedreceive, mqd_t, mqdes, compat_size_t, msg_len, unsigned int __user *, u_msg_prio, const struct compat_timespec __user *, u_abs_timeout) { -struct timespec ts, *p =NULL ; +struct timespec64 ts, *p =NULL ;if (u_abs_timeout) {int res =compat_prepare_timeout (u_abs_timeout, &ts);if (res)kernel/audit.h +1
-1@@ -182,7 +182,7 @@ struct audit_context {mqd_t mqdes;size_t msg_len;unsigned int msg_prio; -struct timespec abs_timeout; +struct timespec64 abs_timeout; } mq_sendrecv;struct {int oflag;kernel/auditsc.c +6
-7@@ -1235,11 +1235,11 @@ static void show_special(struct audit_context *context, int *call_panic)case AUDIT_MQ_SENDRECV :audit_log_format (ab,"mqdes=%d msg_len=%zd msg_prio=%u " -"abs_timeout_sec=%ld abs_timeout_nsec=%ld" , +"abs_timeout_sec=%lld abs_timeout_nsec=%ld" , context->mq_sendrecv.mqdes, context->mq_sendrecv.msg_len, context->mq_sendrecv.msg_prio, - context->mq_sendrecv.abs_timeout.tv_sec, + (long long ) context->mq_sendrecv.abs_timeout.tv_sec, context->mq_sendrecv.abs_timeout.tv_nsec);break ;case AUDIT_MQ_NOTIFY :@@ -2083,15 +2083,15 @@ void __audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr)* */ void __audit_mq_sendrecv (mqd_t mqdes,size_t msg_len,unsigned int msg_prio, -const struct timespec *abs_timeout) +const struct timespec64 *abs_timeout) {struct audit_context *context = current->audit_context; -struct timespec *p = &context->mq_sendrecv.abs_timeout; +struct timespec64 *p = &context->mq_sendrecv.abs_timeout;if (abs_timeout) -memcpy (p, abs_timeout,sizeof (struct timespec )); +memcpy (p, abs_timeout,sizeof (*p));else -memset (p,0 ,sizeof (struct timespec )); +memset (p,0 ,sizeof (*p)); context->mq_sendrecv.mqdes = mqdes; context->mq_sendrecv.msg_len = msg_len; --2.11.0
Signature · 2 lines
paul moore www.paul-moore.com
Re: [PATCH v2 2/6] ipc: mqueue: Replace timespec with timespec64
Quoted 4 lines
The audit bits look fine. Deepa, I assume you are going to seek to have this go in through a tree other than audit?
Acked-by Paul Moore <[email protected]>
Yes, the proposal was to go through Al's tree since he already has a few ipc patches queued up.
Thanks,
Deepa
PATCH v2 3/6 ipc: msg: Make msg_queue timestamps y2038 safe
In reply to Deepa Dinamanitime_t is not y2038 safe. Replace all uses oftime_t by y2038 safe time64_t.
Similarly, replace the calls to get_seconds() with y2038 safe ktime_get_real_seconds().
Note that this preserves fast access on 64 bit systems, but 32 bit systems need sequence counters.
The syscall interfaces themselves are not changed as part of the patch. They will be part of a different series.
--- include/linux/msg.h | 7 ++++--- ipc/msg.c | 12 ++++++------ 2 files changed, 10 insertions(+), 9 deletions(-)
include/linux/msg.h +4 -3
@@ -2,6 +2,7 @@#define _LINUX_MSG_H#include <linux/list.h> +#include <linux/time64.h> #include <uapi/linux/msg.h> /* one msg_msg structure for each message */
@@ -17,9 +18,9 @@ struct msg_msg {/* one msq_queue structure for each present queue on the system */ struct msg_queue {struct kern_ipc_perm q_perm; -time_t q_stime;/* last msgsnd time */ -time_t q_rtime;/* last msgrcv time */ -time_t q_ctime;/* last change time */ +time64_t q_stime;/* last msgsnd time */ +time64_t q_rtime;/* last msgrcv time */ +time64_t q_ctime;/* last change time */ unsigned long q_cbytes;/* current number of bytes on queue */ unsigned long q_qnum;/* number of messages in queue */ unsigned long q_qbytes;/* max number of bytes on queue */
ipc/msg.c +6 -6
@@ -133,7 +133,7 @@ static int newque(struct ipc_namespace *ns, struct ipc_params *params) } msq->q_stime = msq->q_rtime =0 ; - msq->q_ctime =get_seconds (); + msq->q_ctime =ktime_get_real_seconds (); msq->q_cbytes = msq->q_qnum =0 ; msq->q_qbytes = ns->msg_ctlmnb; msq->q_lspid = msq->q_lrpid =0 ;
@@ -406,7 +406,7 @@ static int msgctl_down(struct ipc_namespace *ns, int msqid, int cmd, msq->q_qbytes = msqid64->msg_qbytes; - msq->q_ctime =get_seconds (); + msq->q_ctime =ktime_get_real_seconds ();/* * Sleeping receivers might be excluded by * stricter permissions.
@@ -1181,7 +1181,7 @@ static int sysvipc_msg_proc_show(struct seq_file *s, void *it)struct msg_queue *msq = it; seq_printf(s, - "%10d %10d %4o %10lu %10lu %5u %5u %5u %5u %5u %5u %10lu %10lu %10lu\n", + "%10d %10d %4o %10lu %10lu %5u %5u %5u %5u %5u %5u %10llu %10llu %10llu\n", msq->q_perm.key, msq->q_perm.id, msq->q_perm.mode,
@@ -1193,9 +1193,9 @@ static int sysvipc_msg_proc_show(struct seq_file *s, void *it)from_kgid_munged (user_ns, msq->q_perm.gid),from_kuid_munged (user_ns, msq->q_perm.cuid),from_kgid_munged (user_ns, msq->q_perm.cgid), - msq->q_stime, - msq->q_rtime, - msq->q_ctime); + (unsigned long long ) msq->q_stime, + (unsigned long long ) msq->q_rtime, + (unsigned long long) msq->q_ctime);return 0 ; }
Signature · 1 line
2.11.0
Re: [PATCH v2 3/6] ipc: msg: Make msg_queue timestamps y2038 safe
Quoted 11 lines · Deepa Dinamani
ipc/msg.c +1
-1@@ -1181,7 +1181,7 @@ static int sysvipc_msg_proc_show(struct seq_file *s, void *it)struct msg_queue *msq = it; seq_printf(s, - "%10d %10d %4o %10lu %10lu %5u %5u %5u %5u %5u %5u %10lu %10lu %10lu\n", + "%10d %10d %4o %10lu %10lu %5u %5u %5u %5u %5u %5u %10llu %10llu %10llu\n", msq->q_perm.key, msq->q_perm.id, msq->q_perm.mode,@@ -1193,9 +1193,9 @@ static int sysvipc_msg_proc_show(struct seq_file *s, void *it) from_kgid_munged(user_ns, msq->q_perm.gid),
ipc/msg.c static int sysvipc_msg_proc_show(struct seq_file *s, void *it) · line 1200
Quoted 10 lines
ipc/msg.c +3
-3from_kuid_munged (user_ns, msq->q_perm.cuid),from_kgid_munged (user_ns, msq->q_perm.cgid), - msq->q_stime, - msq->q_rtime, - msq->q_ctime); + (unsigned long long ) msq->q_stime, + (unsigned long long ) msq->q_rtime, + (unsigned long long) msq->q_ctime);return 0 ;
This again can skip the cast, you only need the format change.
Arnd
PATCH v2 4/6 ipc: sem: Make sem_array timestamps y2038 safe
In reply to Deepa Dinamanitime_t is not y2038 safe. Replace all uses oftime_t by y2038 safe time64_t.
Similarly, replace the calls to get_seconds() with y2038 safe ktime_get_real_seconds().
Note that this preserves fast access on 64 bit systems, but 32 bit systems need sequence counters.
The syscall interface themselves are not changed as part of the patch. They will be part of a different series.
--- include/linux/sem.h | 3 ++- ipc/sem.c | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-)
include/linux/sem.h +2 -1
@@ -4,6 +4,7 @@#include <linux/atomic.h> #include <linux/rcupdate.h> #include <linux/cache.h> +#include <linux/time64.h> #include <uapi/linux/sem.h> struct task_struct ;
@@ -11,7 +12,7 @@ struct task_struct;/* One sem_array data structure for each set of semaphores in the system. */ struct sem_array {struct kern_ipc_perm sem_perm;/* permissions .. see ipc.h */ -time_t sem_ctime;/* last change time */ +time64_t sem_ctime;/* last change time */ struct sem *sem_base;/* ptr to first semaphore in array */ struct list_head pending_alter;/* pending operations */ /* that alter the array */
ipc/sem.c +11 -11
@@ -518,7 +518,7 @@ static int newary(struct ipc_namespace *ns, struct ipc_params *params)INIT_LIST_HEAD (&sma->pending_const);INIT_LIST_HEAD (&sma->list_id); sma->sem_nsems = nsems; - sma->sem_ctime =get_seconds (); + sma->sem_ctime =ktime_get_real_seconds (); id =ipc_addid (&sem_ids (ns), &sma->sem_perm, ns->sc_semmni);if (id <0 ) {
@@ -1169,14 +1169,14 @@ static unsigned long copy_semid_to_user(void __user *buf, struct semid64_ds *in, } } -static time_t get_semotime (struct sem_array *sma) +static time64_t get_semotime (struct sem_array *sma) {int i; -time_t res; +time64_t res; res = sma->sem_base[0 ].sem_otime;for (i =1 ; i < sma->sem_nsems; i++) { -time_t to = sma->sem_base[i].sem_otime; +time64_t to = sma->sem_base[i].sem_otime;if (to > res) res = to;
@@ -1316,7 +1316,7 @@ static int semctl_setval(struct ipc_namespace *ns, int semid, int semnum, curr->semval = val; curr->sempid =task_tgid_vnr (current); - sma->sem_ctime =get_seconds (); + sma->sem_ctime =ktime_get_real_seconds ();/* maybe some queued-up processes were waiting for this */ do_smart_update (sma,NULL ,0 ,0 , &wake_q);sem_unlock (sma,-1 );
@@ -1442,7 +1442,7 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,for (i =0 ; i < nsems; i++) un->semadj[i] =0 ; } - sma->sem_ctime =get_seconds (); + sma->sem_ctime =ktime_get_real_seconds ();/* maybe some queued-up processes were waiting for this */ do_smart_update (sma,NULL ,0 ,0 , &wake_q); err =0 ;
@@ -1552,7 +1552,7 @@ static int semctl_down(struct ipc_namespace *ns, int semid, err =ipc_update_perm (&semid64->sem_perm, ipcp);if (err) goto out_unlock0; - sma->sem_ctime =get_seconds (); + sma->sem_ctime =ktime_get_real_seconds ();break ;default : err = -EINVAL ;
@@ -2297,7 +2297,7 @@ static int sysvipc_sem_proc_show(struct seq_file *s, void *it) {struct user_namespace *user_ns =seq_user_ns (s);struct sem_array *sma = it; -time_t sem_otime; +time64_t sem_otime;/* * The proc interface isn't aware of sem_lock(), it calls
@@ -2310,7 +2310,7 @@ static int sysvipc_sem_proc_show(struct seq_file *s, void *it) sem_otime =get_semotime (sma); seq_printf(s, - "%10d %10d %4o %10u %5u %5u %5u %5u %10lu %10lu\n", + "%10d %10d %4o %10u %5u %5u %5u %5u %10llu %10llu\n", sma->sem_perm.key, sma->sem_perm.id, sma->sem_perm.mode,
@@ -2319,8 +2319,8 @@ static int sysvipc_sem_proc_show(struct seq_file *s, void *it)from_kgid_munged (user_ns, sma->sem_perm.gid),from_kuid_munged (user_ns, sma->sem_perm.cuid),from_kgid_munged (user_ns, sma->sem_perm.cgid), - sem_otime, - sma->sem_ctime); + (unsigned long long ) sem_otime, + (unsigned long long) sma->sem_ctime);complexmode_tryleave (sma);
Signature · 1 line
2.11.0
Re: [PATCH v2 4/6] ipc: sem: Make sem_array timestamps y2038 safe
Quoted 8 lines · Deepa Dinamani
time_tis not y2038 safe. Replace all uses oftime_tby y2038 safetime64_t.Similarly, replace the calls to
get_seconds()with y2038 safektime_get_real_seconds().
Note that this preserves fast access on 64 bit systems, but 32 bit systems need sequence counters.
Quoted 4 lines
The syscall interface themselves are not changed as part of the patch. They will be part of a different series.
Signed-off-by Deepa Dinamani <[email protected]>
Looks good. One detail:
Quoted 10 lines
ipc/sem.c +1
-1@@ -2310,7 +2310,7 @@ static int sysvipc_sem_proc_show(struct seq_file *s, void *it) sem_otime =get_semotime (sma); seq_printf(s, - "%10d %10d %4o %10u %5u %5u %5u %5u %10lu %10lu\n", + "%10d %10d %4o %10u %5u %5u %5u %5u %10llu %10llu\n", sma->sem_perm.key, sma->sem_perm.id, sma->sem_perm.mode,
ipc/sem.c static int sysvipc_sem_proc_show(struct seq_file *s, void *it) · line 2324
Quoted 8 lines
ipc/sem.c +2
-2@@ -2319,8 +2319,8 @@ static int sysvipc_sem_proc_show(struct seq_file *s, void *it)from_kgid_munged (user_ns, sma->sem_perm.gid),from_kuid_munged (user_ns, sma->sem_perm.cuid),from_kgid_munged (user_ns, sma->sem_perm.cgid), - sem_otime, - sma->sem_ctime); + (unsigned long long ) sem_otime, + (unsigned long long) sma->sem_ctime);
Unless I'm missing something here, you can drop the cast to unsigned long long: time64_t is always 'long long' and won't cause a warning here.
We only need a cast like this when printing the members of 'struct
timespec64', since that can be either 'long long' or 'long', when
it is defined as an alias for timespec.
Arnd
Re: [PATCH v2 4/6] ipc: sem: Make sem_array timestamps y2038 safe
Quoted 7 lines
Unless I'm missing something here, you can drop the cast to unsigned long long:
time64_tis always 'long long' and won't cause a warning here.We only need a cast like this when printing the members of 'struct
timespec64', since that can be either 'long long' or 'long', when
it is defined as an alias for timespec.
You are right.
I think I had timespec64 on my mind when I added this cast. I will update the series with the casts removed.
Thanks,
Deepa
PATCH v2 5/6 ipc: shm: Make shmid_kernel timestamps y2038 safe
In reply to Deepa Dinamanitime_t is not y2038 safe. Replace all uses oftime_t by y2038 safe time64_t.
Similarly, replace the calls to get_seconds() with y2038 safe ktime_get_real_seconds().
Note that this preserves fast access on 64 bit systems, but 32 bit systems need sequence counters.
The syscall interfaces themselves are not changed as part of the patch. They will be part of a different series.
--- include/linux/shm.h | 6 +++--- ipc/shm.c | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-)
include/linux/shm.h +3 -3
@@ -12,9 +12,9 @@ struct shmid_kernel /* private to the kernel */struct file *shm_file;unsigned long shm_nattch;unsigned long shm_segsz; -time_t shm_atim; -time_t shm_dtim; -time_t shm_ctim; +time64_t shm_atim; +time64_t shm_dtim; +time64_t shm_ctim;pid_t shm_cprid;pid_t shm_lprid;struct user_struct *mlock_user;
ipc/shm.c +8 -8
@@ -199,7 +199,7 @@ static int __shm_open(struct vm_area_struct *vma)if (IS_ERR (shp))return PTR_ERR (shp); - shp->shm_atim =get_seconds (); + shp->shm_atim =ktime_get_real_seconds (); shp->shm_lprid =task_tgid_vnr (current); shp->shm_nattch++;shm_unlock (shp);
@@ -286,7 +286,7 @@ static void shm_close(struct vm_area_struct *vma) goto done;/* no-op */ shp->shm_lprid =task_tgid_vnr (current); - shp->shm_dtim =get_seconds (); + shp->shm_dtim =ktime_get_real_seconds (); shp->shm_nattch--;if (shm_may_destroy (ns, shp))shm_destroy (ns, shp);
@@ -592,7 +592,7 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params) shp->shm_cprid =task_tgid_vnr (current); shp->shm_lprid =0 ; shp->shm_atim = shp->shm_dtim =0 ; - shp->shm_ctim =get_seconds (); + shp->shm_ctim =ktime_get_real_seconds (); shp->shm_segsz = size; shp->shm_nattch =0 ; shp->shm_file = file;
@@ -848,7 +848,7 @@ static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd, err =ipc_update_perm (&shmid64->shm_perm, ipcp);if (err) goto out_unlock0; - shp->shm_ctim =get_seconds (); + shp->shm_ctim =ktime_get_real_seconds ();break ;default : err = -EINVAL ;
@@ -1588,7 +1588,7 @@ static int sysvipc_shm_proc_show(struct seq_file *s, void *it) seq_printf(s, "%10d %10d %4o " SIZE_SPEC " %5u %5u " - "%5lu %5u %5u %5u %5u %10lu %10lu %10lu " + "%5lu %5u %5u %5u %5u %10llu %10llu %10llu " SIZE_SPEC " " SIZE_SPEC "\n", shp->shm_perm.key, shp->shm_perm.id,
@@ -1601,9 +1601,9 @@ static int sysvipc_shm_proc_show(struct seq_file *s, void *it)from_kgid_munged (user_ns, shp->shm_perm.gid),from_kuid_munged (user_ns, shp->shm_perm.cuid),from_kgid_munged (user_ns, shp->shm_perm.cgid), - shp->shm_atim, - shp->shm_dtim, - shp->shm_ctim, + (unsigned long long ) shp->shm_atim, + (unsigned long long ) shp->shm_dtim, + (unsigned long long ) shp->shm_ctim, rss *PAGE_SIZE , swp * PAGE_SIZE);
Signature · 1 line
2.11.0
PATCH v2 6/6 utimes: Make utimes y2038 safe
In reply to Deepa Dinamanistruct timespec is not y2038 safe on 32 bit machines. Replace timespec with y2038 safe struct timespec64.
Note that the patch only changes the internals without modifying the syscall interfaces. This will be part of a separate series.
--- fs/utimes.c | 23 ++++++++++++----------- include/linux/time.h | 2 +- init/initramfs.c | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-)
fs/utimes.c +12 -11
@@ -22,7 +22,7 @@*/ SYSCALL_DEFINE2(utime, char __user *, filename, struct utimbuf __user *, times) { -struct timespec tv[2 ]; +struct timespec64 tv[2 ];if (times) { if (get_user(tv[0].tv_sec, ×->actime) ||
@@ -44,7 +44,7 @@ static bool nsec_valid(long nsec)return nsec >=0 && nsec <=999999999 ; } -static int utimes_common (const struct path *path,struct timespec *times) +static int utimes_common (const struct path *path,struct timespec64 *times) {int error;struct iattr newattrs;
@@ -115,7 +115,7 @@ static int utimes_common(const struct path *path, struct timespec *times)* must be owner or have write permission. * Else, update from *times, must be owner or super user. */ -long do_utimes (int dfd,const char __user *filename,struct timespec *times, +long do_utimes (int dfd,const char __user *filename,struct timespec64 *times,int flags) {int error = -EINVAL ;
@@ -167,10 +167,11 @@ long do_utimes(int dfd, const char __user *filename, struct timespec *times, SYSCALL_DEFINE4(utimensat, int, dfd, const char __user *, filename, struct timespec __user *, utimes, int, flags) { -struct timespec tstimes[2 ]; +struct timespec64 tstimes[2 ];if (utimes) { -if (copy_from_user (&tstimes, utimes,sizeof (tstimes))) +if ((get_timespec64 (&tstimes[0 ], &utimes[0 ]) || +get_timespec64 (&tstimes[1 ], &utimes[1 ])))return -EFAULT ;/* Nothing to do, we must not even check the path. */
@@ -186,7 +187,7 @@ SYSCALL_DEFINE3(futimesat, int, dfd, const char __user *, filename, struct timeval __user *, utimes) {struct timeval times[2 ]; -struct timespec tstimes[2 ]; +struct timespec64 tstimes[2 ];if (utimes) {if (copy_from_user (×, utimes,sizeof (times)))
@@ -224,7 +225,7 @@ SYSCALL_DEFINE2(utimes, char __user *, filename, COMPAT_SYSCALL_DEFINE2(utime, const char __user *, filename, struct compat_utimbuf __user *, t) { -struct timespec tv[2 ]; +struct timespec64 tv[2 ];if (t) { if (get_user(tv[0].tv_sec, &t->actime) ||
@@ -238,11 +239,11 @@ COMPAT_SYSCALL_DEFINE2(utime, const char __user *, filename, COMPAT_SYSCALL_DEFINE4(utimensat, unsigned int, dfd, const char __user *, filename, struct compat_timespec __user *, t, int, flags) { -struct timespec tv[2 ]; +struct timespec64 tv[2 ];if (t) { -if (compat_get_timespec (&tv[0 ], &t[0 ]) || -compat_get_timespec (&tv[1 ], &t[1 ])) +if (compat_get_timespec64 (&tv[0 ], &t[0 ]) || +compat_get_timespec64 (&tv[1 ], &t[1 ]))return -EFAULT ;if (tv[0 ].tv_nsec ==UTIME_OMIT && tv[1 ].tv_nsec ==UTIME_OMIT )
@@ -253,7 +254,7 @@ COMPAT_SYSCALL_DEFINE4(utimensat, unsigned int, dfd, const char __user *, filena COMPAT_SYSCALL_DEFINE3(futimesat, unsigned int, dfd, const char __user *, filename, struct compat_timeval __user *, t) { -struct timespec tv[2 ]; +struct timespec64 tv[2 ];if (t) { if (get_user(tv[0].tv_sec, &t[0].tv_sec) ||
include/linux/time.h +1 -1
@@ -178,7 +178,7 @@ extern int do_setitimer(int which, struct itimerval *value, struct itimerval *ovalue);extern int do_getitimer (int which,struct itimerval *value); -extern long do_utimes (int dfd,const char __user *filename,struct timespec *times,int flags); +extern long do_utimes (int dfd,const char __user *filename,struct timespec64 *times,int flags);/* * Similar to the struct tm in userspace <time.h>, but it needs to be here so
init/initramfs.c +1 -1
@@ -110,7 +110,7 @@ static void __init free_hash(void)static long __init do_utime (char *filename,time_t mtime) { -struct timespec t[2 ]; +struct timespec64 t[2 ]; t[0 ].tv_sec = mtime; t[0 ].tv_nsec =0 ;
Signature · 1 line
2.11.0
Quoted 4 lines · Deepa Dinamani
The series aims to transition internal workings of ipc subsystem to use y2038-safe types and apis.
The series is based on Al Viro's #work.ipc branch.
The series looks all good to me, the only detail I found that can be improved are
a couple of extra typecasts for time64_t printing.