Skip to content

Commit c198b77

Browse files
ukleinekUwe Kleine-König
authored andcommitted
pwm: Ensure ioctl() returns a negative errno on error
copy_to_user() returns the number of bytes not copied, thus if there is a problem a positive number. However the ioctl callback is supposed to return a negative error code on error. This error is a unfortunate as strictly speaking it became ABI with the introduction of pwm character devices. However I never saw the issue in real life -- I found this by code inspection -- and it only affects an error case where readonly memory is passed to the ioctls or the address mapping changes while the ioctl is active. Also there are already error cases returning negative values, so the calling code must be prepared to see such values already. Fixes: 9c06f26 ("pwm: Add support for pwmchip devices for faster and easier userspace access") Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> Link: https://patch.msgid.link/20260119151325.571857-2-u.kleine-koenig@baylibre.com Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
1 parent 8f0b4cc commit c198b77

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

drivers/pwm/core.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,8 +2295,9 @@ static long pwm_cdev_ioctl(struct file *file, unsigned int cmd, unsigned long ar
22952295
.duty_offset_ns = wf.duty_offset_ns,
22962296
};
22972297

2298-
return copy_to_user((struct pwmchip_waveform __user *)arg,
2299-
&cwf, sizeof(cwf));
2298+
ret = copy_to_user((struct pwmchip_waveform __user *)arg,
2299+
&cwf, sizeof(cwf));
2300+
return ret ? -EFAULT : 0;
23002301
}
23012302

23022303
case PWM_IOCTL_GETWF:
@@ -2329,8 +2330,9 @@ static long pwm_cdev_ioctl(struct file *file, unsigned int cmd, unsigned long ar
23292330
.duty_offset_ns = wf.duty_offset_ns,
23302331
};
23312332

2332-
return copy_to_user((struct pwmchip_waveform __user *)arg,
2333-
&cwf, sizeof(cwf));
2333+
ret = copy_to_user((struct pwmchip_waveform __user *)arg,
2334+
&cwf, sizeof(cwf));
2335+
return ret ? -EFAULT : 0;
23342336
}
23352337

23362338
case PWM_IOCTL_SETROUNDEDWF:

0 commit comments

Comments
 (0)