* regression from your recent change to x86's copy_user_handle_tail()
@ 2015-04-22 6:33 Jan Beulich
2015-04-23 15:33 ` Linus Torvalds
0 siblings, 1 reply; 5+ messages in thread
From: Jan Beulich @ 2015-04-22 6:33 UTC (permalink / raw)
To: Linus Torvalds; +Cc: linux-kernel
Linus,
while the description of commit cae2a173fe certainly makes sense, the
change itself ignores the __probe_kernel_write() code path, for which
the destination address is expected to be in kernel space but accesses
may still fault. I.e. the use of plain memset() causes
__probe_kernel_write() to oops rather than return an error. Shouldn't
the "(unsigned long)to >= TASK_SIZE_MAX" be relaxed to take the
effect of set_fs() into account?
Thanks, Jan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: regression from your recent change to x86's copy_user_handle_tail()
2015-04-22 6:33 regression from your recent change to x86's copy_user_handle_tail() Jan Beulich
@ 2015-04-23 15:33 ` Linus Torvalds
2015-04-23 15:43 ` Jan Beulich
2015-04-24 6:51 ` Jan Beulich
0 siblings, 2 replies; 5+ messages in thread
From: Linus Torvalds @ 2015-04-23 15:33 UTC (permalink / raw)
To: Jan Beulich; +Cc: Linux Kernel Mailing List
On Tue, Apr 21, 2015 at 11:33 PM, Jan Beulich <JBeulich@suse.com> wrote:
>
> while the description of commit cae2a173fe certainly makes sense, the
> change itself ignores the __probe_kernel_write() code path, for which
> the destination address is expected to be in kernel space but accesses
> may still fault. I.e. the use of plain memset() causes
> __probe_kernel_write() to oops rather than return an error. Shouldn't
> the "(unsigned long)to >= TASK_SIZE_MAX" be relaxed to take the
> effect of set_fs() into account?
Hmm. I think you're right. So something like
--- a/arch/x86/lib/usercopy_64.c
+++ b/arch/x86/lib/usercopy_64.c
@@ -82,7 +82,7 @@ copy_user_handle_tail(char *to, char *from, unsigned len)
clac();
/* If the destination is a kernel buffer, we always clear the end */
- if ((unsigned long)to >= TASK_SIZE_MAX)
+ if (!__addr_ok(to))
memset(to, 0, len);
return len;
}
which will effectively say "only if we copy from user mode to kernel
mode" because if we use "set_fs(KERNEL_DS)" then kernel addresses will
also be __addr_ok..
Did you have a test-case for this? I guess we're talking odd ftrace
uses or kgdb?
Linus
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: regression from your recent change to x86's copy_user_handle_tail()
2015-04-23 15:33 ` Linus Torvalds
@ 2015-04-23 15:43 ` Jan Beulich
2015-04-23 15:52 ` Linus Torvalds
2015-04-24 6:51 ` Jan Beulich
1 sibling, 1 reply; 5+ messages in thread
From: Jan Beulich @ 2015-04-23 15:43 UTC (permalink / raw)
To: Linus Torvalds; +Cc: Linux Kernel Mailing List
>>> On 23.04.15 at 17:33, <torvalds@linux-foundation.org> wrote:
> On Tue, Apr 21, 2015 at 11:33 PM, Jan Beulich <JBeulich@suse.com> wrote:
>>
>> while the description of commit cae2a173fe certainly makes sense, the
>> change itself ignores the __probe_kernel_write() code path, for which
>> the destination address is expected to be in kernel space but accesses
>> may still fault. I.e. the use of plain memset() causes
>> __probe_kernel_write() to oops rather than return an error. Shouldn't
>> the "(unsigned long)to >= TASK_SIZE_MAX" be relaxed to take the
>> effect of set_fs() into account?
>
> Hmm. I think you're right. So something like
>
> --- a/arch/x86/lib/usercopy_64.c
> +++ b/arch/x86/lib/usercopy_64.c
> @@ -82,7 +82,7 @@ copy_user_handle_tail(char *to, char *from, unsigned len)
> clac();
>
> /* If the destination is a kernel buffer, we always clear the end */
> - if ((unsigned long)to >= TASK_SIZE_MAX)
> + if (!__addr_ok(to))
> memset(to, 0, len);
> return len;
> }
>
> which will effectively say "only if we copy from user mode to kernel
> mode" because if we use "set_fs(KERNEL_DS)" then kernel addresses will
> also be __addr_ok..
>
> Did you have a test-case for this? I guess we're talking odd ftrace
> uses or kgdb?
I'm afraid not one you'd like - we've seen ftrace initialization fail for
quite some time on our Xen kernels, but in a way only affecting
ftrace itself. Said change converted that failure to an oops. (The
ftrace init failure itself is because the traditional Xen kernel creates
1:1 mappings for pages that are part of kernel image as read-only,
to avoid having to special case embedded regions [GDT, page tables]
that must be r/o under Xen. I think the pv-ops kernel behaves
differently, which made me recognize this as a problem wider than
just for our specific Xen case only on second thought.)
Jan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: regression from your recent change to x86's copy_user_handle_tail()
2015-04-23 15:43 ` Jan Beulich
@ 2015-04-23 15:52 ` Linus Torvalds
0 siblings, 0 replies; 5+ messages in thread
From: Linus Torvalds @ 2015-04-23 15:52 UTC (permalink / raw)
To: Jan Beulich; +Cc: Linux Kernel Mailing List
On Thu, Apr 23, 2015 at 8:43 AM, Jan Beulich <JBeulich@suse.com> wrote:
>>
>> Did you have a test-case for this? I guess we're talking odd ftrace
>> uses or kgdb?
>
> I'm afraid not one you'd like - we've seen ftrace initialization fail for
> quite some time on our Xen kernels, but in a way only affecting
> ftrace itself. Said change converted that failure to an oops
So if you have a reproducer and can test the suggested one-liner patch
for it, I don't really are whether I personally consider your odd
test-case "sane" or not ;)
I think the __probe_kernel_write() code path is kind of odd and nasty,
but I think your point was good, and I think the one-liner makes
conceptual sense. So I don't have any problem applying that patch, and
even marking it for stable. I just want to make sure that it gets
tested on that odd (crazy) case, just to validate that there's nothing
else going on.
So I don't need some test-case for *me* to test and care about. I just
want that patch validated so that I can happily commit it with a
tested-by..
Linus
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: regression from your recent change to x86's copy_user_handle_tail()
2015-04-23 15:33 ` Linus Torvalds
2015-04-23 15:43 ` Jan Beulich
@ 2015-04-24 6:51 ` Jan Beulich
1 sibling, 0 replies; 5+ messages in thread
From: Jan Beulich @ 2015-04-24 6:51 UTC (permalink / raw)
To: Linus Torvalds; +Cc: Linux Kernel Mailing List
>>> On 23.04.15 at 17:33, <torvalds@linux-foundation.org> wrote:
> On Tue, Apr 21, 2015 at 11:33 PM, Jan Beulich <JBeulich@suse.com> wrote:
>>
>> while the description of commit cae2a173fe certainly makes sense, the
>> change itself ignores the __probe_kernel_write() code path, for which
>> the destination address is expected to be in kernel space but accesses
>> may still fault. I.e. the use of plain memset() causes
>> __probe_kernel_write() to oops rather than return an error. Shouldn't
>> the "(unsigned long)to >= TASK_SIZE_MAX" be relaxed to take the
>> effect of set_fs() into account?
>
> Hmm. I think you're right. So something like
>
> --- a/arch/x86/lib/usercopy_64.c
> +++ b/arch/x86/lib/usercopy_64.c
> @@ -82,7 +82,7 @@ copy_user_handle_tail(char *to, char *from, unsigned len)
> clac();
>
> /* If the destination is a kernel buffer, we always clear the end */
> - if ((unsigned long)to >= TASK_SIZE_MAX)
> + if (!__addr_ok(to))
> memset(to, 0, len);
> return len;
> }
>
> which will effectively say "only if we copy from user mode to kernel
> mode" because if we use "set_fs(KERNEL_DS)" then kernel addresses will
> also be __addr_ok..
>
> Did you have a test-case for this? I guess we're talking odd ftrace
> uses or kgdb?
So I thought you meant something you could try. The above fixes
the issue for me, i.e.
Tested-by: Jan Beulich <jbeulich@suse.com>
Thanks, Jan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-04-24 6:51 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-22 6:33 regression from your recent change to x86's copy_user_handle_tail() Jan Beulich
2015-04-23 15:33 ` Linus Torvalds
2015-04-23 15:43 ` Jan Beulich
2015-04-23 15:52 ` Linus Torvalds
2015-04-24 6:51 ` Jan Beulich
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®