copy_mount_options() problem
Hello,
copy_mount_options() checks that data doesn't cross TASK_SIZE boundary. It's not correct. Really it should check USER_DS boudary, because some archs have TASK_SIZE not equal to USER_DS. In this case (USER_DS != TASK_SIZE) exact_copy_from_user() will stop on access_ok() check, if data cross USER_DS, but doesn't cross TASK_SIZE.
Best regards,
Pavel V. Panteleev
Al Viro
maintainerQuoted 7 lines · Pavel V. Panteleev
Hello,
copy_mount_options()checks that data doesn't crossTASK_SIZEboundary. It's not correct. Really it should checkUSER_DSboudary, because some archs haveTASK_SIZEnot equal toUSER_DS. In this case (USER_DS!=TASK_SIZE)exact_copy_from_user()will stop onaccess_ok()check, if data crossUSER_DS, but doesn't crossTASK_SIZE.
Details of the call chain, please.
Al Viro
maintainerQuoted 10 lines · Al Viro
Quoted 7 lines · Pavel V. Panteleev
Hello,
copy_mount_options()checks that data doesn't crossTASK_SIZEboundary. It's not correct. Really it should checkUSER_DSboudary, because some archs haveTASK_SIZEnot equal toUSER_DS. In this case (USER_DS!=TASK_SIZE)exact_copy_from_user()will stop onaccess_ok()check, if data crossUSER_DS, but doesn't crossTASK_SIZE.Details of the call chain, please.
FWIW, what I want to do with copy_mount_options() is this:
void *copy_mount_options(const void __user * data)
{
unsigned offs, size;
char *copy;
if (!data)
return NULL;
copy = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!copy)
return ERR_PTR(-ENOMEM);
offs = (unsigned long)data & (PAGE_SIZE - 1);
if (copy_from_user(copy, data, PAGE_SIZE - offs)) {
kfree(copy);
return ERR_PTR(-EFAULT);
}
if (offs) {
if (copy_from_user(copy, data + PAGE_SIZE - offs, offs))
memset(copy + PAGE_SIZE - offs, 0, offs);
}
return copy;
}which should get rid of any TASK_SIZE references whatsoever, but I really wonder where have you run into the problem.
This works, thanks.
Quoted 40 lines · Al Viro
Quoted 9 lines · Al Viro
Quoted 7 lines · Pavel V. Panteleev
Hello,
copy_mount_options()checks that data doesn't crossTASK_SIZEboundary. It's not correct. Really it should checkUSER_DSboudary, because some archs haveTASK_SIZEnot equal toUSER_DS. In this case (USER_DS!=TASK_SIZE)exact_copy_from_user()will stop onaccess_ok()check, if data crossUSER_DS, but doesn't crossTASK_SIZE.Details of the call chain, please.
FWIW, what I want to do with
copy_mount_options()is this:
void *copy_mount_options(const void__user* data){ unsigned offs, size; char *copy; if (!data) return NULL; copy = kmalloc(PAGE_SIZE, GFP_KERNEL); if (!copy) return ERR_PTR(-ENOMEM); offs = (unsigned long)data & (PAGE_SIZE - 1); if (copy_from_user(copy, data, PAGE_SIZE - offs)) { kfree(copy); return ERR_PTR(-EFAULT); } if (offs) { if (copy_from_user(copy, data + PAGE_SIZE - offs, offs)) memset(copy + PAGE_SIZE - offs, 0, offs); } return copy; }which should get rid of any
TASK_SIZEreferences whatsoever, but I really wonder where have you run into the problem.
# tracer: nop
#
# entries-in-buffer/entries-written: 3/3 #P:16
#
# _-----=> irqs-off
# / _----=> need-resched
# |/ _-----=> need-resched_lazy
# || / _---=> hardirq/softirq
# ||| / _--=> preempt-depth
# |||| / _-=> preempt-lazy-depth
# ||||| / _-=> migrate-disable
# |||||| / delay
# TASK-PID CPU# ||||||| TIMESTAMP FUNCTION
# | | | ||||||| | |
automount-5999 [001] ....... 170.320000: 0:
copy_mount_options(): copy 0xd017d560b000 data 0xc2dfffffe340 size 0x1000 USER_DS 0xc2dffffff000 TASK_SIZE 0xd00000000000
automount-5999 [001] ....... 170.320000: :
exact_copy_from_user(): !access_ok
automount-5999 [001] ....... 170.320000: : copy_mount_options(): return -EFAULT
Quoted 11 lines · Al Viro
Quoted 7 lines · Pavel V. Panteleev
Hello,
copy_mount_options()checks that data doesn't crossTASK_SIZEboundary. It's not correct. Really it should checkUSER_DSboudary, because some archs haveTASK_SIZEnot equal toUSER_DS. In this case (USER_DS!=TASK_SIZE)exact_copy_from_user()will stop onaccess_ok()check, if data crossUSER_DS, but doesn't crossTASK_SIZE.Details of the call chain, please.