From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: Yi Xie <xieyi@kylinos.cn>
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] ipc/shm: check shm_lock() in do_shmat cleanup
Date: Sat, 18 Jul 2026 15:02:26 +0100 [thread overview]
Message-ID: <aluHSJWgrCna9yNu@lucifer> (raw)
In-Reply-To: <20260716075330.96378-1-xieyi@kylinos.cn>
On Thu, Jul 16, 2026 at 03:53:30PM +0800, Yi Xie wrote:
> 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>
LGTM, so:
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> ---
Small note - it's useful to put a list of changes per version and links to the
previous versions on lore after the '---' for reviewers. Anything after the ---
and before the patch won't go upstream.
> 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
>
Cheers, Lorenzo
prev parent reply other threads:[~2026-07-18 14:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 7:53 Yi Xie
2026-07-18 3:18 ` Andrew Morton
2026-07-18 14:02 ` Lorenzo Stoakes (ARM) [this message]
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=aluHSJWgrCna9yNu@lucifer \
--to=ljs@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=xieyi@kylinos.cn \
/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®