All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Leo Stone <leocstone@gmail.com>
Cc: syzbot+ff4aab278fa7e27e0f9e@syzkaller.appspotmail.com,
	hch@lst.de, sagi@grimberg.me, kch@nvidia.com,
	linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com,
	linux-nvme@lists.infradead.org
Subject: Re: [PATCH] nvmet: Don't overflow subsysnqn
Date: Wed, 18 Dec 2024 08:19:49 +0100	[thread overview]
Message-ID: <20241218071949.GA25990@lst.de> (raw)
In-Reply-To: <20241218005909.89092-2-leocstone@gmail.com>

On Tue, Dec 17, 2024 at 04:59:10PM -0800, Leo Stone wrote:
> nvmet_root_discovery_nqn_store treats the subsysnqn string like a fixed
> size buffer, even though it is dynamically allocated to the size of the
> string.
> 
> Create a new string with kstrdup instead of using the old buffer.
> 
> Reported-by: syzbot+ff4aab278fa7e27e0f9e@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=ff4aab278fa7e27e0f9e
> Fixes: 95409e277d83 ("nvmet: implement unique discovery NQN")
> Signed-off-by: Leo Stone <leocstone@gmail.com>
> ---
>  drivers/nvme/target/configfs.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
> index eeee9e9b854c..3fa25f9f7d92 100644
> --- a/drivers/nvme/target/configfs.c
> +++ b/drivers/nvme/target/configfs.c
> @@ -2271,8 +2271,8 @@ static ssize_t nvmet_root_discovery_nqn_store(struct config_item *item,
>  			return -EINVAL;
>  		}
>  	}
> -	memset(nvmet_disc_subsys->subsysnqn, 0, NVMF_NQN_FIELD_LEN);
> -	memcpy(nvmet_disc_subsys->subsysnqn, page, len);
> +	kfree(nvmet_disc_subsys->subsysnqn);
> +	nvmet_disc_subsys->subsysnqn = kstrdup(page, GFP_KERNEL);

This needs error handling, pobably best done by using a local
variable for the new allocation, which would also help to keep it
outside the lock.



      reply	other threads:[~2024-12-18  7:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-17 17:47 [syzbot] [kernel?] general protection fault in account_kernel_stack (3) syzbot
2024-12-18  0:59 ` [PATCH] nvmet: Don't overflow subsysnqn Leo Stone
2024-12-18  7:19   ` Christoph Hellwig [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=20241218071949.GA25990@lst.de \
    --to=hch@lst.de \
    --cc=kch@nvidia.com \
    --cc=leocstone@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    --cc=syzbot+ff4aab278fa7e27e0f9e@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.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 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.