Skip to content

Commit 87b318b

Browse files
deepanshu406gregkh
authored andcommitted
comedi: fix divide-by-zero in comedi_buf_munge()
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: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=f6c3c066162d2c43a66c Cc: [email protected] Signed-off-by: Deepanshu Kartikey <[email protected]> Reviewed-by: Ian Abbott <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 98718e8 commit 87b318b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/comedi/comedi_buf.c

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

320-
if (!s->munge || (async->cmd.flags & CMDF_RAWDATA)) {
320+
if (!s->munge || (async->cmd.flags & CMDF_RAWDATA) || async->cmd.chanlist_len == 0) {
321321
async->munge_count += num_bytes;
322322
return num_bytes;
323323
}

0 commit comments

Comments
 (0)