All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] ipc/shm: check shm_lock() in do_shmat cleanup
@ 2026-07-16  7:53 Yi Xie
  2026-07-18  3:18 ` Andrew Morton
  2026-07-18 14:02 ` Lorenzo Stoakes (ARM)
  0 siblings, 2 replies; 3+ messages in thread
From: Yi Xie @ 2026-07-16  7:53 UTC (permalink / raw)
  To: akpm, ljs; +Cc: linux-kernel, Yi Xie

do_shmat() calls shm_lock() in the out_nattch branch and
immediately dereferences it, however shm_lock() can return an
error.

Check for an error and handle it if there is one.

Signed-off-by: Yi Xie <xieyi@kylinos.cn>
---
 ipc/shm.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/ipc/shm.c b/ipc/shm.c
index b3e8a58e177d..d243137c4dbd 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -1677,12 +1677,16 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg,
 out_nattch:
 	down_write(&shm_ids(ns).rwsem);
 	shp = shm_lock(ns, shmid);
-	shp->shm_nattch--;
+	if (IS_ERR(shp)) {
+		err = PTR_ERR(shp);
+	} else {
+		shp->shm_nattch--;
 
-	if (shm_may_destroy(shp))
-		shm_destroy(ns, shp);
-	else
-		shm_unlock(shp);
+		if (shm_may_destroy(shp))
+			shm_destroy(ns, shp);
+		else
+			shm_unlock(shp);
+	}
 	up_write(&shm_ids(ns).rwsem);
 	return err;
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-07-18 14:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-16  7:53 [PATCH v3] ipc/shm: check shm_lock() in do_shmat cleanup Yi Xie
2026-07-18  3:18 ` Andrew Morton
2026-07-18 14:02 ` Lorenzo Stoakes (ARM)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.