aboutsummaryrefslogtreecommitdiffstats
path: root/ipc
diff options
context:
space:
mode:
authorFabian Frederick2016-08-02 16:03:07 -0500
committerLinus Torvalds2016-08-02 16:31:41 -0500
commit9b24fef9f0410fb5364245d6cc2bd044cc064007 (patch)
tree21bf1cc4aeec71d03c7a7ffa7c98435b3acf719d /ipc
parentb5afba2974f9ebbaaa11b5a633e55db9be3cc363 (diff)
downloadkernel-9b24fef9f0410fb5364245d6cc2bd044cc064007.tar.gz
kernel-9b24fef9f0410fb5364245d6cc2bd044cc064007.tar.xz
kernel-9b24fef9f0410fb5364245d6cc2bd044cc064007.zip
sysv, ipc: fix security-layer leaking
Commit 53dad6d3a8e5 ("ipc: fix race with LSMs") updated ipc_rcu_putref() to receive rcu freeing function but used generic ipc_rcu_free() instead of msg_rcu_free() which does security cleaning. Running LTP msgsnd06 with kmemleak gives the following: cat /sys/kernel/debug/kmemleak unreferenced object 0xffff88003c0a11f8 (size 8): comm "msgsnd06", pid 1645, jiffies 4294672526 (age 6.549s) hex dump (first 8 bytes): 1b 00 00 00 01 00 00 00 ........ backtrace: kmemleak_alloc+0x23/0x40 kmem_cache_alloc_trace+0xe1/0x180 selinux_msg_queue_alloc_security+0x3f/0xd0 security_msg_queue_alloc+0x2e/0x40 newque+0x4e/0x150 ipcget+0x159/0x1b0 SyS_msgget+0x39/0x40 entry_SYSCALL_64_fastpath+0x13/0x8f Manfred Spraul suggested to fix sem.c as well and Davidlohr Bueso to only use ipc_rcu_free in case of security allocation failure in newary() Fixes: 53dad6d3a8e ("ipc: fix race with LSMs") Link: http://lkml.kernel.org/r/1470083552-22966-1-git-send-email-fabf@skynet.be Signed-off-by: Fabian Frederick <fabf@skynet.be> Cc: Davidlohr Bueso <dbueso@suse.de> Cc: Manfred Spraul <manfred@colorfullife.com> Cc: <stable@vger.kernel.org> [3.12+] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'ipc')
-rw-r--r--ipc/msg.c2
-rw-r--r--ipc/sem.c12
2 files changed, 7 insertions, 7 deletions
diff --git a/ipc/msg.c b/ipc/msg.c
index 1471db9a7e61..c6521c205cb4 100644
--- a/ipc/msg.c
+++ b/ipc/msg.c
@@ -680,7 +680,7 @@ long do_msgsnd(int msqid, long mtype, void __user *mtext,
680 rcu_read_lock(); 680 rcu_read_lock();
681 ipc_lock_object(&msq->q_perm); 681 ipc_lock_object(&msq->q_perm);
682 682
683 ipc_rcu_putref(msq, ipc_rcu_free); 683 ipc_rcu_putref(msq, msg_rcu_free);
684 /* raced with RMID? */ 684 /* raced with RMID? */
685 if (!ipc_valid_object(&msq->q_perm)) { 685 if (!ipc_valid_object(&msq->q_perm)) {
686 err = -EIDRM; 686 err = -EIDRM;
diff --git a/ipc/sem.c b/ipc/sem.c
index ae72b3cddc8d..7c9d4f7683c0 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -438,7 +438,7 @@ static inline struct sem_array *sem_obtain_object_check(struct ipc_namespace *ns
438static inline void sem_lock_and_putref(struct sem_array *sma) 438static inline void sem_lock_and_putref(struct sem_array *sma)
439{ 439{
440 sem_lock(sma, NULL, -1); 440 sem_lock(sma, NULL, -1);
441 ipc_rcu_putref(sma, ipc_rcu_free); 441 ipc_rcu_putref(sma, sem_rcu_free);
442} 442}
443 443
444static inline void sem_rmid(struct ipc_namespace *ns, struct sem_array *s) 444static inline void sem_rmid(struct ipc_namespace *ns, struct sem_array *s)
@@ -1381,7 +1381,7 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
1381 rcu_read_unlock(); 1381 rcu_read_unlock();
1382 sem_io = ipc_alloc(sizeof(ushort)*nsems); 1382 sem_io = ipc_alloc(sizeof(ushort)*nsems);
1383 if (sem_io == NULL) { 1383 if (sem_io == NULL) {
1384 ipc_rcu_putref(sma, ipc_rcu_free); 1384 ipc_rcu_putref(sma, sem_rcu_free);
1385 return -ENOMEM; 1385 return -ENOMEM;
1386 } 1386 }
1387 1387
@@ -1415,20 +1415,20 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
1415 if (nsems > SEMMSL_FAST) { 1415 if (nsems > SEMMSL_FAST) {
1416 sem_io = ipc_alloc(sizeof(ushort)*nsems); 1416 sem_io = ipc_alloc(sizeof(ushort)*nsems);
1417 if (sem_io == NULL) { 1417 if (sem_io == NULL) {
1418 ipc_rcu_putref(sma, ipc_rcu_free); 1418 ipc_rcu_putref(sma, sem_rcu_free);
1419 return -ENOMEM; 1419 return -ENOMEM;
1420 } 1420 }
1421 } 1421 }
1422 1422
1423 if (copy_from_user(sem_io, p, nsems*sizeof(ushort))) { 1423 if (copy_from_user(sem_io, p, nsems*sizeof(ushort))) {
1424 ipc_rcu_putref(sma, ipc_rcu_free); 1424 ipc_rcu_putref(sma, sem_rcu_free);
1425 err = -EFAULT; 1425 err = -EFAULT;
1426 goto out_free; 1426 goto out_free;
1427 } 1427 }
1428 1428
1429 for (i = 0; i < nsems; i++) { 1429 for (i = 0; i < nsems; i++) {
1430 if (sem_io[i] > SEMVMX) { 1430 if (sem_io[i] > SEMVMX) {
1431 ipc_rcu_putref(sma, ipc_rcu_free); 1431 ipc_rcu_putref(sma, sem_rcu_free);
1432 err = -ERANGE; 1432 err = -ERANGE;
1433 goto out_free; 1433 goto out_free;
1434 } 1434 }
@@ -1720,7 +1720,7 @@ static struct sem_undo *find_alloc_undo(struct ipc_namespace *ns, int semid)
1720 /* step 2: allocate new undo structure */ 1720 /* step 2: allocate new undo structure */
1721 new = kzalloc(sizeof(struct sem_undo) + sizeof(short)*nsems, GFP_KERNEL); 1721 new = kzalloc(sizeof(struct sem_undo) + sizeof(short)*nsems, GFP_KERNEL);
1722 if (!new) { 1722 if (!new) {
1723 ipc_rcu_putref(sma, ipc_rcu_free); 1723 ipc_rcu_putref(sma, sem_rcu_free);
1724 return ERR_PTR(-ENOMEM); 1724 return ERR_PTR(-ENOMEM);
1725 } 1725 }
1726 1726