aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeepa Dinamani <deepa.kernel@gmail.com>2017-08-02 22:51:13 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2017-09-03 20:24:29 -0400
commite54d02b23c5eed3aa0ffe54e659dfe1c9084c262 (patch)
tree2851477ce36dd58453bdc0e339b9f39c2d0427f9
parent50578ea97a2a352c109bd1657e667b212faf2cbb (diff)
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>
-rw-r--r--include/linux/sem.h3
-rw-r--r--ipc/sem.c18
2 files changed, 11 insertions, 10 deletions
diff --git a/include/linux/sem.h b/include/linux/sem.h
index be5cf2ea14ad..867f86f1a20b 100644
--- a/include/linux/sem.h
+++ b/include/linux/sem.h
@@ -4,6 +4,7 @@
4#include <linux/atomic.h> 4#include <linux/atomic.h>
5#include <linux/rcupdate.h> 5#include <linux/rcupdate.h>
6#include <linux/cache.h> 6#include <linux/cache.h>
7#include <linux/time64.h>
7#include <uapi/linux/sem.h> 8#include <uapi/linux/sem.h>
8 9
9struct task_struct; 10struct task_struct;
@@ -30,7 +31,7 @@ struct sem {
30/* One sem_array data structure for each set of semaphores in the system. */ 31/* One sem_array data structure for each set of semaphores in the system. */
31struct sem_array { 32struct sem_array {
32 struct kern_ipc_perm sem_perm; /* permissions .. see ipc.h */ 33 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 */
34 struct list_head pending_alter; /* pending operations */ 35 struct list_head pending_alter; /* pending operations */
35 /* that alter the array */ 36 /* that alter the array */
36 struct list_head pending_const; /* pending complex operations */ 37 struct list_head pending_const; /* pending complex operations */
diff --git a/ipc/sem.c b/ipc/sem.c
index feea26f897e7..f25ea86774c0 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -511,7 +511,7 @@ static int newary(struct ipc_namespace *ns, struct ipc_params *params)
511 INIT_LIST_HEAD(&sma->pending_const); 511 INIT_LIST_HEAD(&sma->pending_const);
512 INIT_LIST_HEAD(&sma->list_id); 512 INIT_LIST_HEAD(&sma->list_id);
513 sma->sem_nsems = nsems; 513 sma->sem_nsems = nsems;
514 sma->sem_ctime = get_seconds(); 514 sma->sem_ctime = ktime_get_real_seconds();
515 515
516 retval = ipc_addid(&sem_ids(ns), &sma->sem_perm, ns->sc_semmni); 516 retval = ipc_addid(&sem_ids(ns), &sma->sem_perm, ns->sc_semmni);
517 if (retval < 0) { 517 if (retval < 0) {
@@ -1162,14 +1162,14 @@ static unsigned long copy_semid_to_user(void __user *buf, struct semid64_ds *in,
1162 } 1162 }
1163} 1163}
1164 1164
1165static time_t get_semotime(struct sem_array *sma) 1165static time64_t get_semotime(struct sem_array *sma)
1166{ 1166{
1167 int i; 1167 int i;
1168 time_t res; 1168 time64_t res;
1169 1169
1170 res = sma->sems[0].sem_otime; 1170 res = sma->sems[0].sem_otime;
1171 for (i = 1; i < sma->sem_nsems; i++) { 1171 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;
1173 1173
1174 if (to > res) 1174 if (to > res)
1175 res = to; 1175 res = to;
@@ -1309,7 +1309,7 @@ static int semctl_setval(struct ipc_namespace *ns, int semid, int semnum,
1309 1309
1310 curr->semval = val; 1310 curr->semval = val;
1311 curr->sempid = task_tgid_vnr(current); 1311 curr->sempid = task_tgid_vnr(current);
1312 sma->sem_ctime = get_seconds(); 1312 sma->sem_ctime = ktime_get_real_seconds();
1313 /* maybe some queued-up processes were waiting for this */ 1313 /* maybe some queued-up processes were waiting for this */
1314 do_smart_update(sma, NULL, 0, 0, &wake_q); 1314 do_smart_update(sma, NULL, 0, 0, &wake_q);
1315 sem_unlock(sma, -1); 1315 sem_unlock(sma, -1);
@@ -1437,7 +1437,7 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
1437 for (i = 0; i < nsems; i++) 1437 for (i = 0; i < nsems; i++)
1438 un->semadj[i] = 0; 1438 un->semadj[i] = 0;
1439 } 1439 }
1440 sma->sem_ctime = get_seconds(); 1440 sma->sem_ctime = ktime_get_real_seconds();
1441 /* maybe some queued-up processes were waiting for this */ 1441 /* maybe some queued-up processes were waiting for this */
1442 do_smart_update(sma, NULL, 0, 0, &wake_q); 1442 do_smart_update(sma, NULL, 0, 0, &wake_q);
1443 err = 0; 1443 err = 0;
@@ -1547,7 +1547,7 @@ static int semctl_down(struct ipc_namespace *ns, int semid,
1547 err = ipc_update_perm(&semid64->sem_perm, ipcp); 1547 err = ipc_update_perm(&semid64->sem_perm, ipcp);
1548 if (err) 1548 if (err)
1549 goto out_unlock0; 1549 goto out_unlock0;
1550 sma->sem_ctime = get_seconds(); 1550 sma->sem_ctime = ktime_get_real_seconds();
1551 break; 1551 break;
1552 default: 1552 default:
1553 err = -EINVAL; 1553 err = -EINVAL;
@@ -2292,7 +2292,7 @@ static int sysvipc_sem_proc_show(struct seq_file *s, void *it)
2292{ 2292{
2293 struct user_namespace *user_ns = seq_user_ns(s); 2293 struct user_namespace *user_ns = seq_user_ns(s);
2294 struct sem_array *sma = it; 2294 struct sem_array *sma = it;
2295 time_t sem_otime; 2295 time64_t sem_otime;
2296 2296
2297 /* 2297 /*
2298 * The proc interface isn't aware of sem_lock(), it calls 2298 * 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)
2305 sem_otime = get_semotime(sma); 2305 sem_otime = get_semotime(sma);
2306 2306
2307 seq_printf(s, 2307 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",
2309 sma->sem_perm.key, 2309 sma->sem_perm.key,
2310 sma->sem_perm.id, 2310 sma->sem_perm.id,
2311 sma->sem_perm.mode, 2311 sma->sem_perm.mode,