ubi: use put_user() when filling the erase counter array

ubi_get_ec_info() checks the user's erase_counters array with
access_ok() and then fills it one entry at a time with __put_user(),
taking the wear-leveling lock for each entry in between.  Each of those
accesses enables and disables user access on its own, so the up-front
check saves nothing.

Use put_user().  The access_ok() stays, so a bad array still fails
before anything is written.

This is part of getting rid of __get_user() and __put_user() entirely.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Linus Torvalds 2026-10-19 19:24:03 -10:00
parent d1280054f8
commit e0d5fa9ae4

View File

@ -861,7 +861,7 @@ static int ubi_get_ec_info(struct ubi_device *ubi, struct ubi_ecinfo_req __user
int ec;
if (ubi_io_is_bad(ubi, peb)) {
if (__put_user(UBI_UNKNOWN, ureq->erase_counters+read_cnt))
if (put_user(UBI_UNKNOWN, ureq->erase_counters+read_cnt))
return -EFAULT;
continue;
@ -877,7 +877,7 @@ static int ubi_get_ec_info(struct ubi_device *ubi, struct ubi_ecinfo_req __user
spin_unlock(&ubi->wl_lock);
if (__put_user(ec, ureq->erase_counters+read_cnt))
if (put_user(ec, ureq->erase_counters+read_cnt))
return -EFAULT;
}