mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pratyush Yadav <p.yadav@ti.com>
To: <Tudor.Ambarus@microchip.com>
Cc: <broonie@kernel.org>, <michael@walle.cc>,
	<miquel.raynal@bootlin.com>, <tkuw584924@gmail.com>,
	<linux-spi@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] spi: spi-mem: check if data buffers are on stack
Date: Tue, 1 Feb 2022 13:32:07 +0530	[thread overview]
Message-ID: <20220201080207.bvqpzemldlvvykga@ti.com> (raw)
In-Reply-To: <366bad2d-ebb3-a2a5-330d-ff9019d18733@microchip.com>

On 01/02/22 07:44AM, Tudor.Ambarus@microchip.com wrote:
> On 1/31/22 13:45, Pratyush Yadav wrote:
> > EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> > 
> > The buffers passed in the data phase must be DMA-able. Programmers often
> > don't realise this requirement and pass in buffers that reside on the
> > stack. This can be hard to spot when reviewing code. Reject ops if their
> > data buffer is on the stack to avoid this.
> > 
> > Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
> > ---
> >  drivers/spi/spi-mem.c | 9 +++++++++
> >  1 file changed, 9 insertions(+)
> > 
> > diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
> > index 37f4443ce9a0..b3793a2979ee 100644
> > --- a/drivers/spi/spi-mem.c
> > +++ b/drivers/spi/spi-mem.c
> > @@ -207,6 +207,15 @@ static int spi_mem_check_op(const struct spi_mem_op *op)
> >             !spi_mem_buswidth_is_valid(op->data.buswidth))
> >                 return -EINVAL;
> > 
> > +       /* Buffers must be DMA-able. */
> > +       if (op->data.dir == SPI_MEM_DATA_IN &&
> > +           object_is_on_stack(op->data.buf.in))
> 
> should we also check if the virt addr is valid?
> if (object_is_on_stack(op->data.buf.in) || !virt_addr_valid(op->data.buf.in))

When would virt addr not be valid? When someone passes a bad pointer? I 
generally have not seen kernel APIs checking for pointer validity (other 
than NULL). If you pass a bad pointer then expect bad things to happen. 
Plus a bad pointer might also point to a valid virtual address, and we 
have no way of catching that. Dunno...

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

      reply	other threads:[~2022-02-01  8:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-31 11:45 Pratyush Yadav
2022-01-31 13:48 ` Miquel Raynal
2022-01-31 13:55 ` Mark Brown
2022-01-31 17:07   ` Pratyush Yadav
2022-01-31 14:49 ` kernel test robot
2022-02-01  7:44 ` Tudor.Ambarus
2022-02-01  8:02   ` Pratyush Yadav [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=20220201080207.bvqpzemldlvvykga@ti.com \
    --to=p.yadav@ti.com \
    --cc=Tudor.Ambarus@microchip.com \
    --cc=broonie@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=michael@walle.cc \
    --cc=miquel.raynal@bootlin.com \
    --cc=tkuw584924@gmail.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®