From: Keith Busch <kbusch@kernel.org>
To: Daniel Wagner <dwagner@suse.de>
Cc: Christoph Hellwig <hch@lst.de>,
"linux-nvme@lists.infradead.org" <linux-nvme@lists.infradead.org>,
Guangwu Zhang <guazhang@redhat.com>,
Ming Lei <ming.lei@redhat.com>,
Oleg Solovyov <mcpain@altlinux.org>
Subject: Re: stack smashing detected with 'nvme sanitize-log /dev/nvme0'
Date: Wed, 23 Aug 2023 09:37:48 -0600 [thread overview]
Message-ID: <ZOYnzFSgWAwnkWqs@kbusch-mbp> (raw)
In-Reply-To: <4ub43j2q4glt42cwgmaf4cohswt4xaz3lna5nquvb5lavjitvv@tctmuwftqil6>
On Tue, Aug 22, 2023 at 09:55:38AM +0200, Daniel Wagner wrote:
> On Mon, Aug 21, 2023 at 09:11:38AM -0600, Keith Busch wrote:
> > I don't think we want to bounce to kernel memory for the device to
> > overwrite it. I suggest just change nvme-cli's stack allocated santize
> > log to a use page aligned and sized buffer.
>
> Sure we can add workarounds in userspace, though I think this is a
> regression and should ideally address in the kernel somehow.
Not sure if this is a regression. Even prior to the DMA alignment
settings change, you'd still hit this if your stack buffer aligned to
512b. The kernel bounce buffer sounds like it just corrupts kernel
memory instead, so we can't have the driver just go back to the way it
was for these devices; someone has to over allocate the buffer.
A device over running their DMA buffer, though, sounds bad enough that a
firmware fix should happen instead.
> > diff --git a/nvme.c b/nvme.c
> > index 181141ad..7f98a506 100644
> > --- a/nvme.c
> > +++ b/nvme.c
> > @@ -2376,7 +2376,7 @@ ret:
> > static int sanitize_log(int argc, char **argv, struct command *command, struct plugin *plugin)
> > {
> > const char *desc = "Retrieve sanitize log and show it.";
> > - struct nvme_sanitize_log_page sanitize_log;
> > + struct nvme_sanitize_log_page *sanitize_log;
> > enum nvme_print_flags flags;
> > struct nvme_dev *dev;
> > int err;
> > @@ -2419,13 +2419,19 @@ static int sanitize_log(int argc, char **argv, struct command *command, struct p
> > if (cfg.human_readable)
> > flags |= VERBOSE;
> >
> > - err = nvme_cli_get_log_sanitize(dev, cfg.rae, &sanitize_log);
> > + if (posix_memalign((void *)&sanitize_log, getpagesize(), 0x1000)) {
> > + err = -1;
> > + goto close_dev;
> > + }
> > +
> > + err = nvme_cli_get_log_sanitize(dev, cfg.rae, sanitize_log);
> > if (!err)
> > - nvme_show_sanitize_log(&sanitize_log, dev->name, flags);
> > + nvme_show_sanitize_log(sanitize_log, dev->name, flags);
> > else if (err > 0)
> > nvme_show_status(err);
> > else
> > nvme_show_error("sanitize status log: %s", nvme_strerror(errno));
> > + free(sanitize_log);
> > close_dev:
> > dev_close(dev);
> > ret:
>
> Anyway, I suppose we want to do this far all get log commands, not sure
> if it is limited to the get sanitize log alone.
Perhaps for saftey we could do that for all logs < 4k in size. There are
not very many of those.
next prev parent reply other threads:[~2023-08-23 15:38 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-26 11:52 stack smashing detected with 'nvme sanitize-log /dev/nvme0' Daniel Wagner
2023-07-26 13:16 ` Christoph Hellwig
2023-08-21 13:37 ` Daniel Wagner
2023-08-21 15:11 ` Keith Busch
2023-08-22 7:55 ` Daniel Wagner
2023-08-23 15:37 ` Keith Busch [this message]
2023-08-25 6:36 ` Daniel Wagner
2023-08-28 9:21 ` Christoph Hellwig
2023-09-25 15:09 ` Daniel Wagner
2023-09-25 15:19 ` Christoph Hellwig
2023-08-28 9:20 ` Christoph Hellwig
2023-08-29 13:29 ` Keith Busch
2023-08-28 9:18 ` Christoph Hellwig
2023-07-27 1:30 ` Ming Lei
2023-07-27 1:37 ` Guangwu Zhang
2023-07-27 7:23 ` Daniel Wagner
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=ZOYnzFSgWAwnkWqs@kbusch-mbp \
--to=kbusch@kernel.org \
--cc=dwagner@suse.de \
--cc=guazhang@redhat.com \
--cc=hch@lst.de \
--cc=linux-nvme@lists.infradead.org \
--cc=mcpain@altlinux.org \
--cc=ming.lei@redhat.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