The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] ipc/shm: check shm_lock() in do_shmat cleanup
@ 2026-07-14  3:17 Yi Xie
  2026-07-14  9:03 ` Lorenzo Stoakes (ARM)
  2026-07-14  9:22 ` [PATCH v2] " Yi Xie
  0 siblings, 2 replies; 4+ messages in thread
From: Yi Xie @ 2026-07-14  3:17 UTC (permalink / raw)
  To: akpm, ljs; +Cc: linux-kernel, Yi Xie

shm_lock() can fail; don't dereference the error pointer.

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

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


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

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

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-14  3:17 [PATCH] ipc/shm: check shm_lock() in do_shmat cleanup Yi Xie
2026-07-14  9:03 ` Lorenzo Stoakes (ARM)
2026-07-14  9:22 ` [PATCH v2] " Yi Xie
2026-07-14  9:30   ` Lorenzo Stoakes (ARM)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox