Skip to content

Commit b904772

Browse files
deepa-hubAl Viro
authored andcommitted
ipc: mqueue: Replace timespec with timespec64
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 <deepa.kernel@gmail.com> Cc: Paul Moore <paul@paul-moore.com> Cc: Richard Guy Briggs <rgb@redhat.com> Reviewed-by: Richard Guy Briggs <rgb@redhat.com> Reviewed-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Paul Moore <paul@paul-moore.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 3ef56dc commit b904772

4 files changed

Lines changed: 24 additions & 24 deletions

File tree

‎include/linux/audit.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ extern int __audit_socketcall(int nargs, unsigned long *args);
351351
extern int __audit_sockaddr(int len, void *addr);
352352
extern void __audit_fd_pair(int fd1, int fd2);
353353
extern void __audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr);
354-
extern void __audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int msg_prio, const struct timespec *abs_timeout);
354+
extern void __audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int msg_prio, const struct timespec64 *abs_timeout);
355355
extern void __audit_mq_notify(mqd_t mqdes, const struct sigevent *notification);
356356
extern void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat);
357357
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)
412412
if (unlikely(!audit_dummy_context()))
413413
__audit_mq_open(oflag, mode, attr);
414414
}
415-
static inline void audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int msg_prio, const struct timespec *abs_timeout)
415+
static inline void audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int msg_prio, const struct timespec64 *abs_timeout)
416416
{
417417
if (unlikely(!audit_dummy_context()))
418418
__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)
549549
{ }
550550
static inline void audit_mq_sendrecv(mqd_t mqdes, size_t msg_len,
551551
unsigned int msg_prio,
552-
const struct timespec *abs_timeout)
552+
const struct timespec64 *abs_timeout)
553553
{ }
554554
static inline void audit_mq_notify(mqd_t mqdes,
555555
const struct sigevent *notification)

‎ipc/mqueue.c‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -668,11 +668,11 @@ static void __do_notify(struct mqueue_inode_info *info)
668668
}
669669

670670
static int prepare_timeout(const struct timespec __user *u_abs_timeout,
671-
struct timespec *ts)
671+
struct timespec64 *ts)
672672
{
673-
if (copy_from_user(ts, u_abs_timeout, sizeof(struct timespec)))
673+
if (get_timespec64(ts, u_abs_timeout))
674674
return -EFAULT;
675-
if (!timespec_valid(ts))
675+
if (!timespec64_valid(ts))
676676
return -EINVAL;
677677
return 0;
678678
}
@@ -962,7 +962,7 @@ static inline void pipelined_receive(struct wake_q_head *wake_q,
962962

963963
static int do_mq_timedsend(mqd_t mqdes, const char __user *u_msg_ptr,
964964
size_t msg_len, unsigned int msg_prio,
965-
struct timespec *ts)
965+
struct timespec64 *ts)
966966
{
967967
struct fd f;
968968
struct inode *inode;
@@ -979,7 +979,7 @@ static int do_mq_timedsend(mqd_t mqdes, const char __user *u_msg_ptr,
979979
return -EINVAL;
980980

981981
if (ts) {
982-
expires = timespec_to_ktime(*ts);
982+
expires = timespec64_to_ktime(*ts);
983983
timeout = &expires;
984984
}
985985

@@ -1080,7 +1080,7 @@ static int do_mq_timedsend(mqd_t mqdes, const char __user *u_msg_ptr,
10801080

10811081
static int do_mq_timedreceive(mqd_t mqdes, char __user *u_msg_ptr,
10821082
size_t msg_len, unsigned int __user *u_msg_prio,
1083-
struct timespec *ts)
1083+
struct timespec64 *ts)
10841084
{
10851085
ssize_t ret;
10861086
struct msg_msg *msg_ptr;
@@ -1092,7 +1092,7 @@ static int do_mq_timedreceive(mqd_t mqdes, char __user *u_msg_ptr,
10921092
struct posix_msg_tree_node *new_leaf = NULL;
10931093

10941094
if (ts) {
1095-
expires = timespec_to_ktime(*ts);
1095+
expires = timespec64_to_ktime(*ts);
10961096
timeout = &expires;
10971097
}
10981098

@@ -1184,7 +1184,7 @@ SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes, const char __user *, u_msg_ptr,
11841184
size_t, msg_len, unsigned int, msg_prio,
11851185
const struct timespec __user *, u_abs_timeout)
11861186
{
1187-
struct timespec ts, *p = NULL;
1187+
struct timespec64 ts, *p = NULL;
11881188
if (u_abs_timeout) {
11891189
int res = prepare_timeout(u_abs_timeout, &ts);
11901190
if (res)
@@ -1198,7 +1198,7 @@ SYSCALL_DEFINE5(mq_timedreceive, mqd_t, mqdes, char __user *, u_msg_ptr,
11981198
size_t, msg_len, unsigned int __user *, u_msg_prio,
11991199
const struct timespec __user *, u_abs_timeout)
12001200
{
1201-
struct timespec ts, *p = NULL;
1201+
struct timespec64 ts, *p = NULL;
12021202
if (u_abs_timeout) {
12031203
int res = prepare_timeout(u_abs_timeout, &ts);
12041204
if (res)
@@ -1475,11 +1475,11 @@ COMPAT_SYSCALL_DEFINE4(mq_open, const char __user *, u_name,
14751475
}
14761476

14771477
static int compat_prepare_timeout(const struct compat_timespec __user *p,
1478-
struct timespec *ts)
1478+
struct timespec64 *ts)
14791479
{
1480-
if (compat_get_timespec(ts, p))
1480+
if (compat_get_timespec64(ts, p))
14811481
return -EFAULT;
1482-
if (!timespec_valid(ts))
1482+
if (!timespec64_valid(ts))
14831483
return -EINVAL;
14841484
return 0;
14851485
}
@@ -1489,7 +1489,7 @@ COMPAT_SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes,
14891489
compat_size_t, msg_len, unsigned int, msg_prio,
14901490
const struct compat_timespec __user *, u_abs_timeout)
14911491
{
1492-
struct timespec ts, *p = NULL;
1492+
struct timespec64 ts, *p = NULL;
14931493
if (u_abs_timeout) {
14941494
int res = compat_prepare_timeout(u_abs_timeout, &ts);
14951495
if (res)
@@ -1504,7 +1504,7 @@ COMPAT_SYSCALL_DEFINE5(mq_timedreceive, mqd_t, mqdes,
15041504
compat_size_t, msg_len, unsigned int __user *, u_msg_prio,
15051505
const struct compat_timespec __user *, u_abs_timeout)
15061506
{
1507-
struct timespec ts, *p = NULL;
1507+
struct timespec64 ts, *p = NULL;
15081508
if (u_abs_timeout) {
15091509
int res = compat_prepare_timeout(u_abs_timeout, &ts);
15101510
if (res)

‎kernel/audit.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ struct audit_context {
182182
mqd_t mqdes;
183183
size_t msg_len;
184184
unsigned int msg_prio;
185-
struct timespec abs_timeout;
185+
struct timespec64 abs_timeout;
186186
} mq_sendrecv;
187187
struct {
188188
int oflag;

‎kernel/auditsc.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,11 +1235,11 @@ static void show_special(struct audit_context *context, int *call_panic)
12351235
case AUDIT_MQ_SENDRECV:
12361236
audit_log_format(ab,
12371237
"mqdes=%d msg_len=%zd msg_prio=%u "
1238-
"abs_timeout_sec=%ld abs_timeout_nsec=%ld",
1238+
"abs_timeout_sec=%lld abs_timeout_nsec=%ld",
12391239
context->mq_sendrecv.mqdes,
12401240
context->mq_sendrecv.msg_len,
12411241
context->mq_sendrecv.msg_prio,
1242-
context->mq_sendrecv.abs_timeout.tv_sec,
1242+
(long long) context->mq_sendrecv.abs_timeout.tv_sec,
12431243
context->mq_sendrecv.abs_timeout.tv_nsec);
12441244
break;
12451245
case AUDIT_MQ_NOTIFY:
@@ -2083,15 +2083,15 @@ void __audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr)
20832083
*
20842084
*/
20852085
void __audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int msg_prio,
2086-
const struct timespec *abs_timeout)
2086+
const struct timespec64 *abs_timeout)
20872087
{
20882088
struct audit_context *context = current->audit_context;
2089-
struct timespec *p = &context->mq_sendrecv.abs_timeout;
2089+
struct timespec64 *p = &context->mq_sendrecv.abs_timeout;
20902090

20912091
if (abs_timeout)
2092-
memcpy(p, abs_timeout, sizeof(struct timespec));
2092+
memcpy(p, abs_timeout, sizeof(*p));
20932093
else
2094-
memset(p, 0, sizeof(struct timespec));
2094+
memset(p, 0, sizeof(*p));
20952095

20962096
context->mq_sendrecv.mqdes = mqdes;
20972097
context->mq_sendrecv.msg_len = msg_len;

0 commit comments

Comments
 (0)