Skip to content

Commit 20114f7

Browse files
author
Al Viro
committed
sanitize audit_mq_notify()
* don't copy_from_user() twice * don't bother with allocations * don't duplicate parts of audit_dummy_context() * make it return void Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 7392906 commit 20114f7

3 files changed

Lines changed: 27 additions & 52 deletions

File tree

‎include/linux/audit.h‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ extern int audit_set_macxattr(const char *name);
453453
extern int __audit_mq_open(int oflag, mode_t mode, struct mq_attr __user *u_attr);
454454
extern int __audit_mq_timedsend(mqd_t mqdes, size_t msg_len, unsigned int msg_prio, const struct timespec __user *u_abs_timeout);
455455
extern int __audit_mq_timedreceive(mqd_t mqdes, size_t msg_len, unsigned int __user *u_msg_prio, const struct timespec __user *u_abs_timeout);
456-
extern int __audit_mq_notify(mqd_t mqdes, const struct sigevent __user *u_notification);
456+
extern void __audit_mq_notify(mqd_t mqdes, const struct sigevent *notification);
457457
extern void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat);
458458
extern int __audit_log_bprm_fcaps(struct linux_binprm *bprm,
459459
const struct cred *new,
@@ -494,11 +494,10 @@ static inline int audit_mq_timedreceive(mqd_t mqdes, size_t msg_len, unsigned in
494494
return __audit_mq_timedreceive(mqdes, msg_len, u_msg_prio, u_abs_timeout);
495495
return 0;
496496
}
497-
static inline int audit_mq_notify(mqd_t mqdes, const struct sigevent __user *u_notification)
497+
static inline void audit_mq_notify(mqd_t mqdes, const struct sigevent *notification)
498498
{
499499
if (unlikely(!audit_dummy_context()))
500-
return __audit_mq_notify(mqdes, u_notification);
501-
return 0;
500+
__audit_mq_notify(mqdes, notification);
502501
}
503502
static inline void audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)
504503
{
@@ -553,7 +552,7 @@ extern int audit_signals;
553552
#define audit_mq_open(o,m,a) ({ 0; })
554553
#define audit_mq_timedsend(d,l,p,t) ({ 0; })
555554
#define audit_mq_timedreceive(d,l,p,t) ({ 0; })
556-
#define audit_mq_notify(d,n) ({ 0; })
555+
#define audit_mq_notify(d,n) ((void)0)
557556
#define audit_mq_getsetattr(d,s) ((void)0)
558557
#define audit_log_bprm_fcaps(b, ncr, ocr) ({ 0; })
559558
#define audit_log_capset(pid, ncr, ocr) ({ 0; })

‎ipc/mqueue.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,17 +1003,17 @@ asmlinkage long sys_mq_notify(mqd_t mqdes,
10031003
struct mqueue_inode_info *info;
10041004
struct sk_buff *nc;
10051005

1006-
ret = audit_mq_notify(mqdes, u_notification);
1007-
if (ret != 0)
1008-
return ret;
1009-
1010-
nc = NULL;
1011-
sock = NULL;
1012-
if (u_notification != NULL) {
1006+
if (u_notification) {
10131007
if (copy_from_user(&notification, u_notification,
10141008
sizeof(struct sigevent)))
10151009
return -EFAULT;
1010+
}
1011+
1012+
audit_mq_notify(mqdes, u_notification ? &notification : NULL);
10161013

1014+
nc = NULL;
1015+
sock = NULL;
1016+
if (u_notification != NULL) {
10171017
if (unlikely(notification.sigev_notify != SIGEV_NONE &&
10181018
notification.sigev_notify != SIGEV_SIGNAL &&
10191019
notification.sigev_notify != SIGEV_THREAD))

‎kernel/auditsc.c‎

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,6 @@ struct audit_aux_data_mq_sendrecv {
139139
struct timespec abs_timeout;
140140
};
141141

142-
struct audit_aux_data_mq_notify {
143-
struct audit_aux_data d;
144-
mqd_t mqdes;
145-
struct sigevent notification;
146-
};
147-
148142
struct audit_aux_data_execve {
149143
struct audit_aux_data d;
150144
int argc;
@@ -246,6 +240,10 @@ struct audit_context {
246240
mqd_t mqdes;
247241
struct mq_attr mqstat;
248242
} mq_getsetattr;
243+
struct {
244+
mqd_t mqdes;
245+
int sigev_signo;
246+
} mq_notify;
249247
};
250248

251249
#if AUDIT_DEBUG
@@ -1267,6 +1265,11 @@ static void show_special(struct audit_context *context, int *call_panic)
12671265
return;
12681266
}
12691267
break; }
1268+
case AUDIT_MQ_NOTIFY: {
1269+
audit_log_format(ab, "mqdes=%d sigev_signo=%d",
1270+
context->mq_notify.mqdes,
1271+
context->mq_notify.sigev_signo);
1272+
break; }
12701273
case AUDIT_MQ_GETSETATTR: {
12711274
struct mq_attr *attr = &context->mq_getsetattr.mqstat;
12721275
audit_log_format(ab,
@@ -1376,14 +1379,6 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts
13761379
axi->abs_timeout.tv_sec, axi->abs_timeout.tv_nsec);
13771380
break; }
13781381

1379-
case AUDIT_MQ_NOTIFY: {
1380-
struct audit_aux_data_mq_notify *axi = (void *)aux;
1381-
audit_log_format(ab,
1382-
"mqdes=%d sigev_signo=%d",
1383-
axi->mqdes,
1384-
axi->notification.sigev_signo);
1385-
break; }
1386-
13871382
case AUDIT_EXECVE: {
13881383
struct audit_aux_data_execve *axi = (void *)aux;
13891384
audit_log_execve_info(context, &ab, axi);
@@ -2274,38 +2269,19 @@ int __audit_mq_timedreceive(mqd_t mqdes, size_t msg_len,
22742269
* @mqdes: MQ descriptor
22752270
* @u_notification: Notification event
22762271
*
2277-
* Returns 0 for success or NULL context or < 0 on error.
22782272
*/
22792273

2280-
int __audit_mq_notify(mqd_t mqdes, const struct sigevent __user *u_notification)
2274+
void __audit_mq_notify(mqd_t mqdes, const struct sigevent *notification)
22812275
{
2282-
struct audit_aux_data_mq_notify *ax;
22832276
struct audit_context *context = current->audit_context;
22842277

2285-
if (!audit_enabled)
2286-
return 0;
2287-
2288-
if (likely(!context))
2289-
return 0;
2290-
2291-
ax = kmalloc(sizeof(*ax), GFP_ATOMIC);
2292-
if (!ax)
2293-
return -ENOMEM;
2294-
2295-
if (u_notification != NULL) {
2296-
if (copy_from_user(&ax->notification, u_notification, sizeof(ax->notification))) {
2297-
kfree(ax);
2298-
return -EFAULT;
2299-
}
2300-
} else
2301-
memset(&ax->notification, 0, sizeof(ax->notification));
2302-
2303-
ax->mqdes = mqdes;
2278+
if (notification)
2279+
context->mq_notify.sigev_signo = notification->sigev_signo;
2280+
else
2281+
context->mq_notify.sigev_signo = 0;
23042282

2305-
ax->d.type = AUDIT_MQ_NOTIFY;
2306-
ax->d.next = context->aux;
2307-
context->aux = (void *)ax;
2308-
return 0;
2283+
context->mq_notify.mqdes = mqdes;
2284+
context->type = AUDIT_MQ_NOTIFY;
23092285
}
23102286

23112287
/**

0 commit comments

Comments
 (0)