mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Wang Yingjie <x-professor@outlook.com>,
	"mkp@kernel.org" <mkp@kernel.org>,
	"axboe@kernel.dk" <axboe@kernel.dk>
Cc: "fujita.tomonori@lab.ntt.co.jp" <fujita.tomonori@lab.ntt.co.jp>,
	"James.Bottomley@HansenPartnership.com"
	<James.Bottomley@HansenPartnership.com>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] scsi: reject negative SG_SET_TIMEOUT values
Date: Mon, 19 Oct 2026 14:34:00 -0700	[thread overview]
Message-ID: <9321a59c-c560-4742-8b71-5b0ec1f30c2f@acm.org> (raw)
In-Reply-To: <20261017084547.2880694-1-x-professor@outlook.com>

On 10/17/26 1:45 AM, Wang Yingjie wrote:
> The block SCSI path predates Git history. The BSG path has exposed the
> same behavior since BSG was introduced.
> 
> Fixes: 3d6392cfbd7d ("bsg: support for full generic block layer SG v3")

As mentioned above this issue is older than when Linus started using git
so I think it would be appropriate to add the following:

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")

> diff --git a/block/bsg.c b/block/bsg.c
> index 82aaf3cee582..681da79a5ba2 100644
> --- a/block/bsg.c
> +++ b/block/bsg.c
> @@ -132,6 +132,8 @@ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
>   	case SG_SET_TIMEOUT:
>   		if (get_user(val, intp))
>   			return -EFAULT;
> +		if (val < 0)
> +			return -EIO;
>   		bd->timeout = clock_t_to_jiffies(val);
>   		return 0;
>   	case SG_GET_TIMEOUT:
> diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c
> index c14f81403a09..162a21112d49 100644
> --- a/drivers/scsi/scsi_ioctl.c
> +++ b/drivers/scsi/scsi_ioctl.c
> @@ -195,10 +195,13 @@ static int sg_set_timeout(struct scsi_device *sdev, int __user *p)
>   {
>   	int timeout, err = get_user(timeout, p);
>   
> -	if (!err)
> -		sdev->sg_timeout = clock_t_to_jiffies(timeout);
> +	if (err)
> +		return err;
> +	if (timeout < 0)
> +		return -EIO;
>   
> -	return err;
> +	sdev->sg_timeout = clock_t_to_jiffies(timeout);
> +	return 0;
>   }

Rejecting negative values with -EIO matches drivers/scsi/sg.c, which
looks good. However, large positive int values still overflow
bd->timeout and sdev->sg_timeout: both fields are 32-bit unsigned int 
while clock_t_to_jiffies() returns unsigned long (clamping only at
ULONG_MAX).

Bart.


  reply	other threads:[~2026-10-19 21:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-17  8:45 Wang Yingjie
2026-10-19 21:34 ` Bart Van Assche [this message]
2026-10-21 18:18   ` [PATCH v2] scsi: handle out-of-range " Wang Yingjie
2026-10-21 20:29     ` Bart Van Assche
2026-10-22  2:55       ` [PATCH v3] " Wang Yingjie
2026-10-22  3:24         ` Bart Van Assche
2026-10-24  3:04         ` Martin K. Petersen
2026-10-29  2:03         ` Martin K. Petersen (Oracle)

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=9321a59c-c560-4742-8b71-5b0ec1f30c2f@acm.org \
    --to=bvanassche@acm.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=axboe@kernel.dk \
    --cc=fujita.tomonori@lab.ntt.co.jp \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mkp@kernel.org \
    --cc=x-professor@outlook.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®