Skip to content

Commit b35534d

Browse files
deepanshu406opsiff
authored andcommitted
comedi: fix divide-by-zero in comedi_buf_munge()
commit 87b318b upstream. 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. 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> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Link: https://patch.msgid.link/20250924102639.1256191-1-kartikey406@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit d4854eff25efb06d0d84c13e7129bbdba4125f8c) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 32cd6cd commit b35534d

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

drivers/comedi/comedi_buf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ static unsigned int comedi_buf_munge(struct comedi_subdevice *s,
368368
unsigned int count = 0;
369369
const unsigned int num_sample_bytes = comedi_bytes_per_sample(s);
370370

371-
if (!s->munge || (async->cmd.flags & CMDF_RAWDATA)) {
371+
if (!s->munge || (async->cmd.flags & CMDF_RAWDATA) || async->cmd.chanlist_len == 0) {
372372
async->munge_count += num_bytes;
373373
return num_bytes;
374374
}

0 commit comments

Comments
 (0)