projects/linux·commit e0d5fa9a

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

e0d5fa9a · Linus Torvalds <[email protected]> · 2026-10-19 19:24:03 -10:00

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 <[email protected]>
Commit
e0d5fa9ae40bedfce4a7b7b2f6ec22096650ffdf
Parents
d1280054

Changes

1 files changed · +2 −2

FileStatusAddDelContent
drivers/mtd/ubi/cdev.cmodified+2−2View file

drivers/mtd/ubi/cdev.c

View file
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index 54acd83..8dd005e 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -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;
}