linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [x86] copy_from{to}_user question
@ 2015-08-12  9:01 yalin wang
  2015-08-12 10:07 ` Borislav Petkov
  0 siblings, 1 reply; 13+ messages in thread
From: yalin wang @ 2015-08-12  9:01 UTC (permalink / raw)
  To: Thomas Gleixner, mingo, hpa, x86, bp, open list, Will Deacon

hi x86 maintainers,

i have a question about copy_from{to}_user() function,
i find on other platforms like arm/ arm64 /hexagon,
all copy_from{to}_user function only check source address for
copy_from and only check to address for copy_to user function,
never check both source and dest together,

but on x86 platform, i see copy_from{to}_user use a generic function
named copy_user_generic_unrolled() in arch/x86/lib/copy_user_64.S,

it check source and dest address no matter it is copy_from user or
copy_to_user ,  is it correct? 
for copy_from_user i think only need check source address is enough,
if check both address, may hide some kernel BUG, if the kernel address
is not valid, because the fix up code will fix it and kernel will
not panic in this situation.

another problems is that in ./fs/proc/kcore.c ,
read_kcore() function:


if (kern_addr_valid(start)) {
          unsigned long n;
  
          n = copy_to_user(buffer, (char *)start, tsz);
          /*                                                                                                                                                                                               
          ¦* We cannot distinguish between fault on source
          ¦* and fault on destination. When this happens
          ¦* we clear too and hope it will trigger the
          ¦* EFAULT again.
          ¦*/ 
          if (n) { 
                  if (clear_user(buffer + tsz - n,
                                          n)) 
                          return -EFAULT;
          }   
  } else {
          if (clear_user(buffer, tsz))
                  return -EFAULT;
  }

it relies on copy_to_user() can fault on both user and kernel address,
it is not true on arm / arm64 /hexgon platforms, maybe some other platforms,
i don’t check all platform code.
and this code may result in kernel panic on these platforms.

i think x86’s copy_from{to}_user code need to change like other platforms.
or am i missing something ?

Thanks










^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2015-08-24 12:05 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-12  9:01 [x86] copy_from{to}_user question yalin wang
2015-08-12 10:07 ` Borislav Petkov
2015-08-13 10:04   ` yalin wang
2015-08-13 16:43     ` Borislav Petkov
2015-08-17  3:27       ` yalin wang
2015-08-17  4:16         ` Borislav Petkov
2015-08-20  8:58           ` yalin wang
2015-08-20 18:22           ` H. Peter Anvin
2015-08-21  4:35             ` Borislav Petkov
2015-08-21 21:06               ` H. Peter Anvin
2015-08-22  9:05                 ` Borislav Petkov
2015-08-24  7:52                   ` yalin wang
2015-08-24 12:05                     ` Jeff Epler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).