Skip to content

Commit e54d02b

Browse files
deepa-hubAl Viro
authored andcommitted
ipc: sem: Make sem_array timestamps y2038 safe
time_t is not y2038 safe. Replace all uses of time_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. Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com> Reviewed-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 50578ea commit e54d02b

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

‎include/linux/sem.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <linux/atomic.h>
55
#include <linux/rcupdate.h>
66
#include <linux/cache.h>
7+
#include <linux/time64.h>
78
#include <uapi/linux/sem.h>
89

910
struct task_struct;
@@ -30,7 +31,7 @@ struct sem {
3031
/* One sem_array data structure for each set of semaphores in the system. */
3132
struct sem_array {
3233
struct kern_ipc_perm sem_perm; /* permissions .. see ipc.h */
33-
time_t sem_ctime; /* create/last semctl() time */
34+
time64_t sem_ctime; /* create/last semctl() time */
3435
struct list_head pending_alter; /* pending operations */
3536
/* that alter the array */
3637
struct list_head pending_const; /* pending complex operations */

‎ipc/sem.c‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ static int newary(struct ipc_namespace *ns, struct ipc_params *params)
511511
INIT_LIST_HEAD(&sma->pending_const);
512512
INIT_LIST_HEAD(&sma->list_id);
513513
sma->sem_nsems = nsems;
514-
sma->sem_ctime = get_seconds();
514+
sma->sem_ctime = ktime_get_real_seconds();
515515

516516
retval = ipc_addid(&sem_ids(ns), &sma->sem_perm, ns->sc_semmni);
517517
if (retval < 0) {
@@ -1162,14 +1162,14 @@ static unsigned long copy_semid_to_user(void __user *buf, struct semid64_ds *in,
11621162
}
11631163
}
11641164

1165-
static time_t get_semotime(struct sem_array *sma)
1165+
static time64_t get_semotime(struct sem_array *sma)
11661166
{
11671167
int i;
1168-
time_t res;
1168+
time64_t res;
11691169

11701170
res = sma->sems[0].sem_otime;
11711171
for (i = 1; i < sma->sem_nsems; i++) {
1172-
time_t to = sma->sems[i].sem_otime;
1172+
time64_t to = sma->sems[i].sem_otime;
11731173

11741174
if (to > res)
11751175
res = to;
@@ -1309,7 +1309,7 @@ static int semctl_setval(struct ipc_namespace *ns, int semid, int semnum,
13091309

13101310
curr->semval = val;
13111311
curr->sempid = task_tgid_vnr(current);
1312-
sma->sem_ctime = get_seconds();
1312+
sma->sem_ctime = ktime_get_real_seconds();
13131313
/* maybe some queued-up processes were waiting for this */
13141314
do_smart_update(sma, NULL, 0, 0, &wake_q);
13151315
sem_unlock(sma, -1);
@@ -1437,7 +1437,7 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
14371437
for (i = 0; i < nsems; i++)
14381438
un->semadj[i] = 0;
14391439
}
1440-
sma->sem_ctime = get_seconds();
1440+
sma->sem_ctime = ktime_get_real_seconds();
14411441
/* maybe some queued-up processes were waiting for this */
14421442
do_smart_update(sma, NULL, 0, 0, &wake_q);
14431443
err = 0;
@@ -1547,7 +1547,7 @@ static int semctl_down(struct ipc_namespace *ns, int semid,
15471547
err = ipc_update_perm(&semid64->sem_perm, ipcp);
15481548
if (err)
15491549
goto out_unlock0;
1550-
sma->sem_ctime = get_seconds();
1550+
sma->sem_ctime = ktime_get_real_seconds();
15511551
break;
15521552
default:
15531553
err = -EINVAL;
@@ -2292,7 +2292,7 @@ static int sysvipc_sem_proc_show(struct seq_file *s, void *it)
22922292
{
22932293
struct user_namespace *user_ns = seq_user_ns(s);
22942294
struct sem_array *sma = it;
2295-
time_t sem_otime;
2295+
time64_t sem_otime;
22962296

22972297
/*
22982298
* The proc interface isn't aware of sem_lock(), it calls
@@ -2305,7 +2305,7 @@ static int sysvipc_sem_proc_show(struct seq_file *s, void *it)
23052305
sem_otime = get_semotime(sma);
23062306

23072307
seq_printf(s,
2308-
"%10d %10d %4o %10u %5u %5u %5u %5u %10lu %10lu\n",
2308+
"%10d %10d %4o %10u %5u %5u %5u %5u %10llu %10llu\n",
23092309
sma->sem_perm.key,
23102310
sma->sem_perm.id,
23112311
sma->sem_perm.mode,

0 commit comments

Comments
 (0)