mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ethan Tidmore <ethantidmore06@gmail.com>
To: akpm@linux-foundation.org
Cc: lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com,
	brauner@kernel.org, linux-kernel@vger.kernel.org,
	Ethan Tidmore <ethantidmore06@gmail.com>
Subject: [PATCH] ipc: Fix error pointer dereference
Date: Tue, 17 Feb 2026 19:17:07 -0600	[thread overview]
Message-ID: <20260218011707.581042-1-ethantidmore06@gmail.com> (raw)

The function shm_lock() can return an error pointer and is not checked
for one. Add check for error pointer.

Detected by Smatch:
ipc/shm.c:1678 do_shmat() error:
'shp' dereferencing possible ERR_PTR()

Fixes: 00c2bf85d8feb ("ipc: get rid of ipc_lock_down()")
Signed-off-by: Ethan Tidmore <ethantidmore06@gmail.com>
---
 ipc/shm.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/ipc/shm.c b/ipc/shm.c
index e8c7d1924c50..d4554f4e7063 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -1675,12 +1675,15 @@ 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)) {
+		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.53.0


             reply	other threads:[~2026-02-18  1:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-18  1:17 Ethan Tidmore [this message]
2026-02-23 17:33 ` Liam R. Howlett

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260218011707.581042-1-ethantidmore06@gmail.com \
    --to=ethantidmore06@gmail.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lorenzo.stoakes@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®