<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-toradex.git/arch/x86/lib/usercopy_32.c, branch v3.2.34</title>
<subtitle>Linux kernel for Apalis and Colibri modules</subtitle>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/'/>
<entry>
<title>x86: Turn the copy_from_user check into an (optional) compile time warning</title>
<updated>2009-10-01T09:31:04+00:00</updated>
<author>
<name>Arjan van de Ven</name>
<email>arjan@infradead.org</email>
</author>
<published>2009-09-30T11:05:23+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=4a3127693001c61a21d1ce680db6340623f52e93'/>
<id>4a3127693001c61a21d1ce680db6340623f52e93</id>
<content type='text'>
A previous patch added the buffer size check to copy_from_user().

One of the things learned from analyzing the result of the previous
patch is that in general, gcc is really good at proving that the
code contains sufficient security checks to not need to do a
runtime check. But that for those cases where gcc could not prove
this, there was a relatively high percentage of real security
issues.

This patch turns the case of "gcc cannot prove" into a compile time
warning, as long as a sufficiently new gcc is in use that supports
this. The objective is that these warnings will trigger developers
checking new cases out before a security hole enters a linux kernel
release.

Signed-off-by: Arjan van de Ven &lt;arjan@linux.intel.com&gt;
Cc: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Cc: "David S. Miller" &lt;davem@davemloft.net&gt;
Cc: James Morris &lt;jmorris@namei.org&gt;
Cc: Jan Beulich &lt;jbeulich@novell.com&gt;
LKML-Reference: &lt;20090930130523.348ae6c4@infradead.org&gt;
Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
A previous patch added the buffer size check to copy_from_user().

One of the things learned from analyzing the result of the previous
patch is that in general, gcc is really good at proving that the
code contains sufficient security checks to not need to do a
runtime check. But that for those cases where gcc could not prove
this, there was a relatively high percentage of real security
issues.

This patch turns the case of "gcc cannot prove" into a compile time
warning, as long as a sufficiently new gcc is in use that supports
this. The objective is that these warnings will trigger developers
checking new cases out before a security hole enters a linux kernel
release.

Signed-off-by: Arjan van de Ven &lt;arjan@linux.intel.com&gt;
Cc: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Cc: "David S. Miller" &lt;davem@davemloft.net&gt;
Cc: James Morris &lt;jmorris@namei.org&gt;
Cc: Jan Beulich &lt;jbeulich@novell.com&gt;
LKML-Reference: &lt;20090930130523.348ae6c4@infradead.org&gt;
Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>x86: Use __builtin_object_size() to validate the buffer size for copy_from_user()</title>
<updated>2009-09-26T14:25:41+00:00</updated>
<author>
<name>Arjan van de Ven</name>
<email>arjan@infradead.org</email>
</author>
<published>2009-09-26T12:33:01+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=9f0cf4adb6aa0bfccf675c938124e68f7f06349d'/>
<id>9f0cf4adb6aa0bfccf675c938124e68f7f06349d</id>
<content type='text'>
gcc (4.x) supports the __builtin_object_size() builtin, which
reports the size of an object that a pointer point to, when known
at compile time. If the buffer size is not known at compile time, a
constant -1 is returned.

This patch uses this feature to add a sanity check to
copy_from_user(); if the target buffer is known to be smaller than
the copy size, the copy is aborted and a WARNing is emitted in
memory debug mode.

These extra checks compile away when the object size is not known,
or if both the buffer size and the copy length are constants.

Signed-off-by: Arjan van de Ven &lt;arjan@linux.intel.com&gt;
LKML-Reference: &lt;20090926143301.2c396b94@infradead.org&gt;
Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
gcc (4.x) supports the __builtin_object_size() builtin, which
reports the size of an object that a pointer point to, when known
at compile time. If the buffer size is not known at compile time, a
constant -1 is returned.

This patch uses this feature to add a sanity check to
copy_from_user(); if the target buffer is known to be smaller than
the copy size, the copy is aborted and a WARNing is emitted in
memory debug mode.

These extra checks compile away when the object size is not known,
or if both the buffer size and the copy length are constants.

Signed-off-by: Arjan van de Ven &lt;arjan@linux.intel.com&gt;
LKML-Reference: &lt;20090926143301.2c396b94@infradead.org&gt;
Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix congestion_wait() sync/async vs read/write confusion</title>
<updated>2009-07-10T18:31:53+00:00</updated>
<author>
<name>Jens Axboe</name>
<email>jens.axboe@oracle.com</email>
</author>
<published>2009-07-09T12:52:32+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=8aa7e847d834ed937a9ad37a0f2ad5b8584c1ab0'/>
<id>8aa7e847d834ed937a9ad37a0f2ad5b8584c1ab0</id>
<content type='text'>
Commit 1faa16d22877f4839bd433547d770c676d1d964c accidentally broke
the bdi congestion wait queue logic, causing us to wait on congestion
for WRITE (== 1) when we really wanted BLK_RW_ASYNC (== 0) instead.

Signed-off-by: Jens Axboe &lt;jens.axboe@oracle.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Commit 1faa16d22877f4839bd433547d770c676d1d964c accidentally broke
the bdi congestion wait queue logic, causing us to wait on congestion
for WRITE (== 1) when we really wanted BLK_RW_ASYNC (== 0) instead.

Signed-off-by: Jens Axboe &lt;jens.axboe@oracle.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>x86: use early clobbers in usercopy*.c</title>
<updated>2009-01-21T08:43:17+00:00</updated>
<author>
<name>Andi Kleen</name>
<email>andi@firstfloor.org</email>
</author>
<published>2009-01-16T14:22:11+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=e0a96129db574d6365e3439d16d88517c437ab33'/>
<id>e0a96129db574d6365e3439d16d88517c437ab33</id>
<content type='text'>
Impact: fix rare (but currently harmless) miscompile with certain configs and gcc versions

Hugh Dickins noticed that strncpy_from_user() was miscompiled
in some circumstances with gcc 4.3.

Thanks to Hugh's excellent analysis it was easy to track down.

Hugh writes:

&gt; Try building an x86_64 defconfig 2.6.29-rc1 kernel tree,
&gt; except not quite defconfig, switch CONFIG_PREEMPT_NONE=y
&gt; and CONFIG_PREEMPT_VOLUNTARY off (because it expands a
&gt; might_fault() there, which hides the issue): using a
&gt; gcc 4.3.2 (I've checked both openSUSE 11.1 and Fedora 10).
&gt;
&gt; It generates the following:
&gt;
&gt; 0000000000000000 &lt;__strncpy_from_user&gt;:
&gt;    0:   48 89 d1                mov    %rdx,%rcx
&gt;    3:   48 85 c9                test   %rcx,%rcx
&gt;    6:   74 0e                   je     16 &lt;__strncpy_from_user+0x16&gt;
&gt;    8:   ac                      lods   %ds:(%rsi),%al
&gt;    9:   aa                      stos   %al,%es:(%rdi)
&gt;    a:   84 c0                   test   %al,%al
&gt;    c:   74 05                   je     13 &lt;__strncpy_from_user+0x13&gt;
&gt;    e:   48 ff c9                dec    %rcx
&gt;   11:   75 f5                   jne    8 &lt;__strncpy_from_user+0x8&gt;
&gt;   13:   48 29 c9                sub    %rcx,%rcx
&gt;   16:   48 89 c8                mov    %rcx,%rax
&gt;   19:   c3                      retq
&gt;
&gt; Observe that "sub %rcx,%rcx; mov %rcx,%rax", whereas gcc 4.2.1
&gt; (and many other configs) say "sub %rcx,%rdx; mov %rdx,%rax".
&gt; Isn't it returning 0 when it ought to be returning strlen?

The asm constraints for the strncpy_from_user() result were missing an
early clobber, which tells gcc that the last output arguments
are written before all input arguments are read.

Also add more early clobbers in the rest of the file and fix 32-bit
usercopy.c in the same way.

Signed-off-by: Andi Kleen &lt;ak@linux.intel.com&gt;
Signed-off-by: H. Peter Anvin &lt;hpa@zytor.com&gt;
[ since this API is rarely used and no in-kernel user relies on a 'len'
  return value (they only rely on negative return values) this miscompile
  was never noticed in the field. But it's worth fixing it nevertheless. ]
Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Impact: fix rare (but currently harmless) miscompile with certain configs and gcc versions

Hugh Dickins noticed that strncpy_from_user() was miscompiled
in some circumstances with gcc 4.3.

Thanks to Hugh's excellent analysis it was easy to track down.

Hugh writes:

&gt; Try building an x86_64 defconfig 2.6.29-rc1 kernel tree,
&gt; except not quite defconfig, switch CONFIG_PREEMPT_NONE=y
&gt; and CONFIG_PREEMPT_VOLUNTARY off (because it expands a
&gt; might_fault() there, which hides the issue): using a
&gt; gcc 4.3.2 (I've checked both openSUSE 11.1 and Fedora 10).
&gt;
&gt; It generates the following:
&gt;
&gt; 0000000000000000 &lt;__strncpy_from_user&gt;:
&gt;    0:   48 89 d1                mov    %rdx,%rcx
&gt;    3:   48 85 c9                test   %rcx,%rcx
&gt;    6:   74 0e                   je     16 &lt;__strncpy_from_user+0x16&gt;
&gt;    8:   ac                      lods   %ds:(%rsi),%al
&gt;    9:   aa                      stos   %al,%es:(%rdi)
&gt;    a:   84 c0                   test   %al,%al
&gt;    c:   74 05                   je     13 &lt;__strncpy_from_user+0x13&gt;
&gt;    e:   48 ff c9                dec    %rcx
&gt;   11:   75 f5                   jne    8 &lt;__strncpy_from_user+0x8&gt;
&gt;   13:   48 29 c9                sub    %rcx,%rcx
&gt;   16:   48 89 c8                mov    %rcx,%rax
&gt;   19:   c3                      retq
&gt;
&gt; Observe that "sub %rcx,%rcx; mov %rcx,%rax", whereas gcc 4.2.1
&gt; (and many other configs) say "sub %rcx,%rdx; mov %rdx,%rax".
&gt; Isn't it returning 0 when it ought to be returning strlen?

The asm constraints for the strncpy_from_user() result were missing an
early clobber, which tells gcc that the last output arguments
are written before all input arguments are read.

Also add more early clobbers in the rest of the file and fix 32-bit
usercopy.c in the same way.

Signed-off-by: Andi Kleen &lt;ak@linux.intel.com&gt;
Signed-off-by: H. Peter Anvin &lt;hpa@zytor.com&gt;
[ since this API is rarely used and no in-kernel user relies on a 'len'
  return value (they only rely on negative return values) this miscompile
  was never noticed in the field. But it's worth fixing it nevertheless. ]
Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Merge commit 'v2.6.28-rc2' into core/locking</title>
<updated>2008-10-28T15:54:49+00:00</updated>
<author>
<name>Ingo Molnar</name>
<email>mingo@elte.hu</email>
</author>
<published>2008-10-28T15:54:49+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=d1a76187a5be4f89c6cb19d800cb5fb7aac735c5'/>
<id>d1a76187a5be4f89c6cb19d800cb5fb7aac735c5</id>
<content type='text'>
Conflicts:
	arch/um/include/asm/system.h
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Conflicts:
	arch/um/include/asm/system.h
</pre>
</div>
</content>
</entry>
<entry>
<title>x86: some lock annotations for user copy paths, v3</title>
<updated>2008-09-11T19:42:59+00:00</updated>
<author>
<name>Ingo Molnar</name>
<email>mingo@elte.hu</email>
</author>
<published>2008-09-11T18:53:21+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=1d18ef489509314506328b9e464dd47c24c1d68f'/>
<id>1d18ef489509314506328b9e464dd47c24c1d68f</id>
<content type='text'>
- add annotation back to clear_user()
- change probe_kernel_address() to _inatomic*() method

Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
- add annotation back to clear_user()
- change probe_kernel_address() to _inatomic*() method

Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>x86: some lock annotations for user copy paths, v2</title>
<updated>2008-09-11T07:44:21+00:00</updated>
<author>
<name>Nick Piggin</name>
<email>npiggin@suse.de</email>
</author>
<published>2008-09-10T11:37:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=3ee1afa308f2a38e5d1e2ad3752ad7abcf480da1'/>
<id>3ee1afa308f2a38e5d1e2ad3752ad7abcf480da1</id>
<content type='text'>
 - introduce might_fault()
 - handle the atomic user copy paths correctly

[ mingo@elte.hu: move might_sleep() outside of in_atomic(). ]
Signed-off-by: Nick Piggin &lt;npiggin@suse.de&gt;
Acked-by: Peter Zijlstra &lt;a.p.zijlstra@chello.nl&gt;
Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
 - introduce might_fault()
 - handle the atomic user copy paths correctly

[ mingo@elte.hu: move might_sleep() outside of in_atomic(). ]
Signed-off-by: Nick Piggin &lt;npiggin@suse.de&gt;
Acked-by: Peter Zijlstra &lt;a.p.zijlstra@chello.nl&gt;
Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>x86: some lock annotations for user copy paths</title>
<updated>2008-09-10T11:48:49+00:00</updated>
<author>
<name>Nick Piggin</name>
<email>npiggin@suse.de</email>
</author>
<published>2008-09-10T11:37:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=c10d38dda1774ed4540380333cabd229eff37094'/>
<id>c10d38dda1774ed4540380333cabd229eff37094</id>
<content type='text'>
copy_to/from_user and all its variants (except the atomic ones) can take a
page fault and perform non-trivial work like taking mmap_sem and entering
the filesyste/pagecache.

Unfortunately, this often escapes lockdep because a common pattern is to
use it to read in some arguments just set up from userspace, or write data
back to a hot buffer. In those cases, it will be unlikely for page reclaim
to get a window in to cause copy_*_user to fault.

With the new might_lock primitives, add some annotations to x86. I don't
know if I caught all possible faulting points (it's a bit of a maze, and I
didn't really look at 32-bit). But this is a starting point.

Boots and runs OK so far.

Signed-off-by: Nick Piggin &lt;npiggin@suse.de&gt;
Acked-by: Peter Zijlstra &lt;a.p.zijlstra@chello.nl&gt;
Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
copy_to/from_user and all its variants (except the atomic ones) can take a
page fault and perform non-trivial work like taking mmap_sem and entering
the filesyste/pagecache.

Unfortunately, this often escapes lockdep because a common pattern is to
use it to read in some arguments just set up from userspace, or write data
back to a hot buffer. In those cases, it will be unlikely for page reclaim
to get a window in to cause copy_*_user to fault.

With the new might_lock primitives, add some annotations to x86. I don't
know if I caught all possible faulting points (it's a bit of a maze, and I
didn't really look at 32-bit). But this is a starting point.

Boots and runs OK so far.

Signed-off-by: Nick Piggin &lt;npiggin@suse.de&gt;
Acked-by: Peter Zijlstra &lt;a.p.zijlstra@chello.nl&gt;
Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>x86: make movsl_mask definition non-CPU specific</title>
<updated>2008-08-18T14:05:45+00:00</updated>
<author>
<name>Thomas Petazzoni</name>
<email>thomas.petazzoni@free-electrons.com</email>
</author>
<published>2008-08-18T10:33:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=8bfcb3960fde049b863266dab8c3617bb5a541aa'/>
<id>8bfcb3960fde049b863266dab8c3617bb5a541aa</id>
<content type='text'>
movsl_mask is currently defined in arch/x86/kernel/cpu/intel.c, which
contains code specific to Intel CPUs. However, movsl_mask is used in
the non-CPU specific code in arch/x86/lib/usercopy_32.c, which breaks
the compilation when support for Intel CPUs is compiled out.

This patch solves this problem by moving movsl_mask's definition close
to its users in arch/x86/lib/usercopy_32.c.

Signed-off-by: Thomas Petazzoni &lt;thomas.petazzoni@free-electrons.com&gt;
Cc: michael@free-electrons.com
Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
movsl_mask is currently defined in arch/x86/kernel/cpu/intel.c, which
contains code specific to Intel CPUs. However, movsl_mask is used in
the non-CPU specific code in arch/x86/lib/usercopy_32.c, which breaks
the compilation when support for Intel CPUs is compiled out.

This patch solves this problem by moving movsl_mask's definition close
to its users in arch/x86/lib/usercopy_32.c.

Signed-off-by: Thomas Petazzoni &lt;thomas.petazzoni@free-electrons.com&gt;
Cc: michael@free-electrons.com
Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>x86: coding style fixes to arch/x86/lib/usercopy_32.c</title>
<updated>2008-04-17T15:40:51+00:00</updated>
<author>
<name>Paolo Ciarrocchi</name>
<email>paolo.ciarrocchi@gmail.com</email>
</author>
<published>2008-02-29T11:50:56+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=3f50dbc1aec96c4d66ffa1c564014f9f43fb9e11'/>
<id>3f50dbc1aec96c4d66ffa1c564014f9f43fb9e11</id>
<content type='text'>
Before:
 total: 63 errors, 2 warnings, 878 lines checked
After:
 total: 0 errors, 2 warnings, 878 lines checked

Compile tested, no change in the binary output:

text    data     bss     dec     hex filename
3231       0       0    3231     c9f usercopy_32.o.after
3231       0       0    3231     c9f usercopy_32.o.before

md5sum:
9f9a3eb43970359ae7cecfd1c9e7cf42  usercopy_32.o.after
9f9a3eb43970359ae7cecfd1c9e7cf42  usercopy_32.o.before

Signed-off-by: Paolo Ciarrocchi &lt;paolo.ciarrocchi@gmail.com&gt;
Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Before:
 total: 63 errors, 2 warnings, 878 lines checked
After:
 total: 0 errors, 2 warnings, 878 lines checked

Compile tested, no change in the binary output:

text    data     bss     dec     hex filename
3231       0       0    3231     c9f usercopy_32.o.after
3231       0       0    3231     c9f usercopy_32.o.before

md5sum:
9f9a3eb43970359ae7cecfd1c9e7cf42  usercopy_32.o.after
9f9a3eb43970359ae7cecfd1c9e7cf42  usercopy_32.o.before

Signed-off-by: Paolo Ciarrocchi &lt;paolo.ciarrocchi@gmail.com&gt;
Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
</pre>
</div>
</content>
</entry>
</feed>
