From: Ian Abbott <abbotti@mev.co.uk>
To: Deepanshu Kartikey <kartikey406@gmail.com>,
H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
syzbot+f6c3c066162d2c43a66c@syzkaller.appspotmail.com
Subject: Re: [PATCH] comedi: fix divide-by-zero in comedi_buf_munge()
Date: Wed, 24 Sep 2025 10:03:54 +0100 [thread overview]
Message-ID: <3f7b60e8-9df8-414a-afd2-2caca7d43209@mev.co.uk> (raw)
In-Reply-To: <20250924015606.1098345-1-kartikey406@gmail.com>
On 24/09/2025 02:56, Deepanshu Kartikey wrote:
> The comedi_buf_munge() function performs a modulo operation
> `async->munge_chan %= async->cmd.chanlist_len` without first
> checking if chanlist_len is zero. If a user program submits
> a command with chanlist_len set to zero, this causes a
> divide-by-zero error when the device processes data in the
> interrupt handler path.
I don't think it should happen for supported hardware devices that are
working properly, but it helps to defend against the unexpected.
> Add a check for zero chanlist_len at the beginning of the
> function, similar to the existing checks for !map and
> CMDF_RAWDATA flag. When chanlist_len is zero, update
> munge_count and return early, indicating the data was
> handled without munging.
>
> This prevents potential kernel panics from malformed user commands.
>
> Reported-by: syzbot+f6c3c066162d2c43a66c@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=f6c3c066162d2c43a66c
> Cc: stable@vger.kernel.org
> Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
> ---
> drivers/comedi/comedi_buf.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/comedi/comedi_buf.c b/drivers/comedi/comedi_buf.c
> index 002c0e76baff..786f888299ce 100644
> --- a/drivers/comedi/comedi_buf.c
> +++ b/drivers/comedi/comedi_buf.c
> @@ -321,6 +321,11 @@ static unsigned int comedi_buf_munge(struct comedi_subdevice *s,
> async->munge_count += num_bytes;
> return num_bytes;
> }
> +
> + if (async->cmd.chanlist_len == 0) {
> + async->munge_count += num_bytes;
> + return num_bytes;
> + }
This `if` statement could be merged with the preceding `if` statement
that has the same body, which would save a few lines.
>
> /* don't munge partial samples */
> num_bytes -= num_bytes % num_sample_bytes;
--
-=( Ian Abbott <abbotti@mev.co.uk> || MEV Ltd. is a company )=-
-=( registered in England & Wales. Regd. number: 02862268. )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-
next prev parent reply other threads:[~2025-09-24 10:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-24 1:56 Deepanshu Kartikey
2025-09-24 9:03 ` Ian Abbott [this message]
[not found] <20250924014929.1097959-1-kartikey406@gmail.com>
2025-09-24 1:49 ` syzbot
[not found] <20250924014724.1097866-1-kartikey406@gmail.com>
2025-09-24 1:47 ` syzbot
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=3f7b60e8-9df8-414a-afd2-2caca7d43209@mev.co.uk \
--to=abbotti@mev.co.uk \
--cc=gregkh@linuxfoundation.org \
--cc=hsweeten@visionengravers.com \
--cc=kartikey406@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=syzbot+f6c3c066162d2c43a66c@syzkaller.appspotmail.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®