Skip to contentSkip to conversation

copy_mount_options() problem

DISCUSSION Pavel V. Panteleev 2 participants 5 messages Oct 15, 2019 – Oct 16, 2019 VFS

lore
Share & tools
lore
#0 lore raw

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

maintainer
#1 lore raw
Quoted 7 lines · Pavel V. Panteleev

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.

Details of the call chain, please.

maintainer
#2 lore raw
Quoted 10 lines · Al Viro
Quoted 7 lines · Pavel V. Panteleev

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.

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.

#3 lore raw

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 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.

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.

#4 lore raw
In reply to Al Viro

# 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 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.

Details of the call chain, please.