mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
To: Kees Cook <keescook@chromium.org>, Jens Axboe <axboe@kernel.dk>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>,
	James Bottomley <James.Bottomley@hansenpartnership.com>,
	Tejun Heo <tj@kernel.org>, Borislav Petkov <bp@alien8.de>,
	"David S. Miller" <davem@davemloft.net>,
	"Manoj N. Kumar" <manoj@linux.vnet.ibm.com>,
	"Matthew R. Ochs" <mrochs@linux.vnet.ibm.com>,
	Uma Krishnan <ukrishn@linux.vnet.ibm.com>,
	linux-block@vger.kernel.org, linux-ide@vger.kernel.org,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 6/6] scsi: Check sense buffer size at build time
Date: Wed, 23 May 2018 11:25:45 +0300	[thread overview]
Message-ID: <7de525d4-52f4-80f2-1f55-a3a5c37d7bf9@cogentembedded.com> (raw)
In-Reply-To: <20180522181512.39316-7-keescook@chromium.org>

Hello!

On 5/22/2018 9:15 PM, Kees Cook wrote:

> To avoid introducing problems like those fixed in commit f7068114d45e
> ("sr: pass down correctly sized SCSI sense buffer"), this creates a macro
> wrapper for scsi_execute() that verifies the size of the sense buffer
> similar to what was done for command string sizes in commit 3756f6401c30
> ("exec: avoid gcc-8 warning for get_task_comm").
> 
> Another solution could be to add another argument to scsi_execute(),
> but this function already takes a lot of arguments and Jens was not fond
> of that approach. As there was only a pair of dynamically allocated sense
> buffers, this also moves those 96 bytes onto the stack to avoid triggering
> the sizeof() check.
> 
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>   drivers/scsi/scsi_lib.c    |  6 +++---
>   include/scsi/scsi_device.h | 12 +++++++++++-
>   2 files changed, 14 insertions(+), 4 deletions(-)
> 
[...]
> diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
> index 7ae177c8e399..1bb87b6c0ad2 100644
> --- a/include/scsi/scsi_device.h
> +++ b/include/scsi/scsi_device.h
> @@ -426,11 +426,21 @@ extern const char *scsi_device_state_name(enum scsi_device_state);
>   extern int scsi_is_sdev_device(const struct device *);
>   extern int scsi_is_target_device(const struct device *);
>   extern void scsi_sanitize_inquiry_string(unsigned char *s, int len);
> -extern int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
> +extern int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
>   			int data_direction, void *buffer, unsigned bufflen,
>   			unsigned char *sense, struct scsi_sense_hdr *sshdr,
>   			int timeout, int retries, u64 flags,
>   			req_flags_t rq_flags, int *resid);
> +/* Make sure any sense buffer is the correct size. */
> +#define scsi_execute(sdev, cmd, data_direction, buffer, bufflen, sense,	\
> +		     sshdr, timeout, retries, flags, rq_flags, resid)	\
> +({									\
> +	BUILD_BUG_ON((sense) != NULL &&					\
> +		     sizeof(sense) != SCSI_SENSE_BUFFERSIZE);		\

    This would only check the size of the 'sense' pointer, no?

> +	__scsi_execute(sdev, cmd, data_direction, buffer, bufflen,	\
> +		       sense, sshdr, timeout, retries, flags, rq_flags,	\
> +		       resid);						\
> +})
>   static inline int scsi_execute_req(struct scsi_device *sdev,
>   	const unsigned char *cmd, int data_direction, void *buffer,
>   	unsigned bufflen, struct scsi_sense_hdr *sshdr, int timeout,

MBR, Sergei

  reply	other threads:[~2018-05-23  8:25 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-22 18:15 [PATCH 0/6] block: Consolidate scsi sense buffer usage Kees Cook
2018-05-22 18:15 ` [PATCH 1/6] ide-cd: Drop unused sense buffers Kees Cook
2018-05-22 18:41   ` Christoph Hellwig
2018-05-22 18:15 ` [PATCH 2/6] scsi: cxlflash: " Kees Cook
2018-05-22 18:41   ` Christoph Hellwig
2018-05-22 21:03   ` Matthew R. Ochs
2018-05-22 18:15 ` [PATCH 3/6] block: Create scsi_sense.h for SCSI and ATAPI Kees Cook
2018-05-22 18:36   ` Christoph Hellwig
2018-05-22 18:50     ` Martin K. Petersen
2018-05-22 18:59       ` Kees Cook
2018-05-22 19:09         ` Jens Axboe
2018-05-22 19:13           ` Christoph Hellwig
2018-05-22 19:16             ` Jens Axboe
2018-05-22 23:31               ` Kees Cook
2018-05-22 23:34                 ` Randy Dunlap
2018-05-22 23:39                   ` Kees Cook
2018-05-22 23:41                     ` Randy Dunlap
2018-05-22 23:42                 ` Jens Axboe
2018-05-22 23:49                   ` Kees Cook
2018-05-23 14:13                     ` Jens Axboe
2018-05-23 14:25                       ` Christoph Hellwig
2018-05-23 14:31                         ` Jens Axboe
2018-05-23 20:52                           ` Kees Cook
2018-05-23 21:06                             ` Martin K. Petersen
2018-05-23 21:17                               ` Kees Cook
2018-05-24  7:36                                 ` Christoph Hellwig
2018-05-23 21:14                             ` Jens Axboe
2018-05-23 21:20                               ` Randy Dunlap
2018-05-23 21:22                                 ` Jens Axboe
2018-05-23 21:23                                   ` Randy Dunlap
2018-05-24  8:00                               ` Christoph Hellwig
2018-05-24 17:06                                 ` Kees Cook
2018-05-25 14:48                                   ` Christoph Hellwig
2018-07-08 20:23                                   ` Christoph Hellwig
2018-07-09 15:56                                     ` Kees Cook
2018-07-31  7:53                                       ` Christoph Hellwig
2018-07-31 19:52                                         ` Kees Cook
2018-05-22 18:15 ` [PATCH 4/6] block: Consolidate scsi sense buffer usage Kees Cook
2018-05-22 18:15 ` [PATCH 5/6] libata-scsi: Move sense buffers onto stack Kees Cook
2018-05-22 18:15 ` [PATCH 6/6] scsi: Check sense buffer size at build time Kees Cook
2018-05-23  8:25   ` Sergei Shtylyov [this message]
2018-05-23 21:08     ` Kees Cook
2018-05-24 14:11   ` Christoph Hellwig

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=7de525d4-52f4-80f2-1f55-a3a5c37d7bf9@cogentembedded.com \
    --to=sergei.shtylyov@cogentembedded.com \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=axboe@kernel.dk \
    --cc=bp@alien8.de \
    --cc=davem@davemloft.net \
    --cc=keescook@chromium.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=manoj@linux.vnet.ibm.com \
    --cc=martin.petersen@oracle.com \
    --cc=mrochs@linux.vnet.ibm.com \
    --cc=tj@kernel.org \
    --cc=ukrishn@linux.vnet.ibm.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®