Skip to content

Commit acb2505

Browse files
author
Al Viro
committed
openrisc: fix copy_from_user()
... that should zero on faults. Also remove the <censored> helpful logics wrt range truncation copied from ppc32. Where it had ever been needed only in case of copy_from_user() *and* had not been merged into the mainline until a month after the need had disappeared. A decade before openrisc went into mainline, I might add... Cc: [email protected] Signed-off-by: Al Viro <[email protected]>
1 parent 2e29f50 commit acb2505

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

arch/openrisc/include/asm/uaccess.h

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -273,28 +273,20 @@ __copy_tofrom_user(void *to, const void *from, unsigned long size);
273273
static inline unsigned long
274274
copy_from_user(void *to, const void *from, unsigned long n)
275275
{
276-
unsigned long over;
277-
278-
if (access_ok(VERIFY_READ, from, n))
279-
return __copy_tofrom_user(to, from, n);
280-
if ((unsigned long)from < TASK_SIZE) {
281-
over = (unsigned long)from + n - TASK_SIZE;
282-
return __copy_tofrom_user(to, from, n - over) + over;
283-
}
284-
return n;
276+
unsigned long res = n;
277+
278+
if (likely(access_ok(VERIFY_READ, from, n)))
279+
n = __copy_tofrom_user(to, from, n);
280+
if (unlikely(res))
281+
memset(to + (n - res), 0, res);
282+
return res;
285283
}
286284

287285
static inline unsigned long
288286
copy_to_user(void *to, const void *from, unsigned long n)
289287
{
290-
unsigned long over;
291-
292-
if (access_ok(VERIFY_WRITE, to, n))
293-
return __copy_tofrom_user(to, from, n);
294-
if ((unsigned long)to < TASK_SIZE) {
295-
over = (unsigned long)to + n - TASK_SIZE;
296-
return __copy_tofrom_user(to, from, n - over) + over;
297-
}
288+
if (likely(access_ok(VERIFY_WRITE, to, n)))
289+
n = __copy_tofrom_user(to, from, n);
298290
return n;
299291
}
300292

@@ -303,13 +295,8 @@ extern unsigned long __clear_user(void *addr, unsigned long size);
303295
static inline __must_check unsigned long
304296
clear_user(void *addr, unsigned long size)
305297
{
306-
307-
if (access_ok(VERIFY_WRITE, addr, size))
308-
return __clear_user(addr, size);
309-
if ((unsigned long)addr < TASK_SIZE) {
310-
unsigned long over = (unsigned long)addr + size - TASK_SIZE;
311-
return __clear_user(addr, size - over) + over;
312-
}
298+
if (likely(access_ok(VERIFY_WRITE, addr, size)))
299+
size = __clear_user(addr, size);
313300
return size;
314301
}
315302

0 commit comments

Comments
 (0)