Hang in SIOCGIFCONF ioctl handler
Hello,
While investigating the Debian bug #288180 [0] (both SMP and UP sparc64 machines lock up hard when starting NIS with 2.6.8-10), I've traced the hang to the handler of SIOCGIFCONF ioctl, dev_ifconf function in fs/compat_ioctl.c. The problem happens in the following code snippet (line numbers refer to the pristine 2.6.10 kernel tree):
510 size_t len =((ifc32.ifc_len / sizeof (struct ifreq32)) + 1) *
511 sizeof (struct ifreq);
512 uifc = compat_alloc_user_space(sizeof(struct ifconf) + len);
513 ifc.ifc_len = len;
514 ifr = ifc.ifc_req = (void __user *)(uifc + 1);
515 ifr32 = compat_ptr(ifc32.ifcbuf);
516 for (i = 0; i < ifc32.ifc_len; i += sizeof (struct ifreq32)) {517 if (copy_in_user(ifr, ifr32, sizeof(struct ifreq32)))
518 return -EFAULT;
519 ifr++;
520 ifr32++;
521 }
By inserting some debugging statements, I was able to figure out that machine hangs because at some point the call to copy_in_user function does not return. As I have no idea why it would block, I wonder if anyone can offer any advice. This code was introduced about 9 months ago [1]. If I revert this patch, everything seems to be working again (no hang).
On an unrelated note, during my exploration I came across the function copy_in_user_fixup in arch/sparc64/lib/user_fixup.c. In this function (and in other functions in that file) copying is done using a loop like this:
while(size--) {
...
}
return size;I am pretty sure that this function is supposed to follow the same error reporting convention as copy_in_user, i.e. return 0 on success, non-zero on error. As they are written now, the loop will stop at size = 0, but it will return -1 due to extra decrement, which is not what one would expect.
Best regards,
[0] http://bugs.debian.org/288180
[1] http://linux.bkbits.net:8080/linux-2.6/diffs/fs/[email protected]?nav=index.html|src/|src/fs|hist/fs/compat_ioctl.c
Jurij Smakov [email protected]
Key: http://www.wooyd.org/pgpkey/ KeyID: C99E03CC
Quoted 13 lines · On Mon, 7 Feb 2005 13:21:16 -0500 (EST) Jurij Smakov <[email protected]> wrote:
510
size_tlen =((ifc32.ifc_len / sizeof (struct ifreq32)) + 1) *
511 sizeof (struct ifreq);512 uifc = compat_alloc_user_space(sizeof(struct ifconf) + len); 513 ifc.ifc_len = len; 514 ifr = ifc.ifc_req = (void __user *)(uifc + 1); 515 ifr32 = compat_ptr(ifc32.ifcbuf); 516 for (i = 0; i < ifc32.ifc_len; i += sizeof (struct ifreq32)) {517 if (
copy_in_user(ifr, ifr32, sizeof(struct ifreq32)))
518 return-EFAULT;
519 ifr++;
520 ifr32++;
521 }
Quoted 3 lines
By inserting some debugging statements, I was able to figure out that machine hangs because at some point the call to
copy_in_userfunction does not return.
How big are the values "ifc32.ifc_len" and the length passed into the compat_alloc_user_space() call for the failure case?
Quoted 9 lines · On Mon, 7 Feb 2005 13:21:16 -0500 (EST) Jurij Smakov <[email protected]> wrote:
On an unrelated note, during my exploration I came across the function
copy_in_user_fixupinarch/sparc64/lib/user_fixup.c. In this function (and in other functions in that file) copying is done using a loop like this:while(size--) { ... } return size;
Quoted 4 lines
I am pretty sure that this function is supposed to follow the same error reporting convention as
copy_in_user, i.e. return 0 on success, non-zero on error. As they are written now, the loop will stop at size = 0, but it will return -1 due to extra decrement, which is not what one would expect.
Right, it's buggy. Good spotting. This should fix it up:
=== arch/sparc64/lib/user_fixup.c 1.1 vs edited ==--- 1.1/arch/sparc64/lib/user_fixup.c 2004-08-23 14:32:55 -07:00
+++ edited/arch/sparc64/lib/user_fixup.c 2005-02-07 11:32:54 -08:00
@@ -20,11 +20,12 @@
char *dst = to;
const char __user *src = from;
- while (size--) {
+ while (size) {
if (__get_user(*dst, src))
break;
dst++;
src++;
+ size--;
}
if (size)
@@ -38,11 +39,12 @@
char __user *dst = to;
const char *src = from;
- while (size--) {
+ while (size) {
if (__put_user(*src, dst))
break;
dst++;
src++;
+ size--;
}
return size;
@@ -53,7 +55,7 @@
char __user *dst = to;
char __user *src = from;
- while (size--) {
+ while (size) {
char tmp;
if (__get_user(tmp, src))
@@ -62,6 +64,7 @@
break;
dst++;
src++;
+ size--;
}
return size;
Quoted 16 lines · David S. Miller
Quoted 13 lines · On Mon, 7 Feb 2005 13:21:16 -0500 (EST) Jurij Smakov <[email protected]> wrote:
510
size_tlen =((ifc32.ifc_len / sizeof (struct ifreq32)) + 1) *
511 sizeof (struct ifreq);512 uifc = compat_alloc_user_space(sizeof(struct ifconf) + len); 513 ifc.ifc_len = len; 514 ifr = ifc.ifc_req = (void __user *)(uifc + 1); 515 ifr32 = compat_ptr(ifc32.ifcbuf); 516 for (i = 0; i < ifc32.ifc_len; i += sizeof (struct ifreq32)) {517 if (
copy_in_user(ifr, ifr32, sizeof(struct ifreq32)))
518 return-EFAULT;
519 ifr++;
520 ifr32++;
521 }
Quoted 6 lines
Quoted 3 lines
By inserting some debugging statements, I was able to figure out that machine hangs because at some point the call to
copy_in_userfunction does not return.How big are the values "ifc32.ifc_len" and the length passed into the
compat_alloc_user_space()call for the failure case?
Hi Dave,
I have inserted the printk statements before, after and inside the loop. The debugging output (including the previous successfull execution of the loop) right before the hang looks like this:
dev_ifconf[516]: alloc_size056 ifc.ifc_len040 ifc32.ifc_lenˆ00 dev_ifconf[518]: i=0 ifr 000000713163f8 ifr32 00000071319050 dev_ifconf[518]: i2 ifr 00000071316420 ifr32 00000071319070 dev_ifconf[518]: id ifr 00000071316448 ifr32 00000071319090 dev_ifconf[518]: i– ifr 00000071316470 ifr32 000000713190b0 [...]
dev_ifconf[518]: i‡36 ifr 00000071318ea0 ifr32 0000007131b270 dev_ifconf[518]: i‡68 ifr 00000071318ec8 ifr32 0000007131b290 dev_ifconf[524]: after loop
dev_ifconf[516]: alloc_size056 ifc.ifc_len040 ifc32.ifc_lenˆ00 dev_ifconf[518]: i=0 ifr 000001efffacf8 ifr32 000000efffd898
alloc_size is the amount allocated by compat_alloc_user_space(). The only "strange" thing I can notice is the ifr address. On a few previous calls to this function starting ifr (at i=0) looks like that:
ifr 000000efffb3b0
ifr 000000efffacc0
ifr 000000efffb328
ifr 000000efffb2b8
and so on. The ifr address right before the hang has an extra bit set.
I hope it helps,
Jurij Smakov [email protected]
Key: http://www.wooyd.org/pgpkey/ KeyID: C99E03CC
Quoted 6 lines · On Mon, 7 Feb 2005 22:34:44 -0500 (EST) Jurij Smakov <[email protected]> wrote:
dev_ifconf[518]: i=0 ifr 000001efffacf8 ifr32 000000efffd898
alloc_sizeis the amount allocated bycompat_alloc_user_space(). The only "strange" thing I can notice is the ifr address. On a few previous calls to this function starting ifr (at i=0) looks like that:
Quoted 6 lines
ifr 000000efffb3b0
ifr 000000efffacc0
ifr 000000efffb328
ifr 000000efffb2b8and so on. The ifr address right before the hang has an extra bit set.
Yep, and notice that the "extra bit" is (1 << 32), or the first bit in the upper 32-bits of the 64-bit kernel pointer. In short, we get garbage from the upper 32-bits of the stack pointer, and need to mask it out for 32-bit tasks. The fix is obvious, try this:
=== include/asm-sparc64/compat.h 1.17 vs edited ==--- 1.17/include/asm-sparc64/compat.h 2005-02-02 04:05:45 -08:00
+++ edited/include/asm-sparc64/compat.h 2005-02-07 19:51:15 -08:00
@@ -133,6 +133,8 @@
if (!(test_thread_flag(TIF_32BIT)))
usp += STACK_BIAS;
+ else
+ usp &= 0xffffffffUL;
return (void __user *) (usp - len);
}
Quoted 8 lines · David S. Miller
Yep, and notice that the "extra bit" is (1 << 32), or the first bit in the upper 32-bits of the 64-bit kernel pointer. In short, we get garbage from the upper 32-bits of the stack pointer, and need to mask it out for 32-bit tasks. The fix is obvious, try this:
===
include/asm-sparc64/compat.h1.17 vs edited ==> ---1.17/include/asm-sparc64/compat.h2005-02-02 04:05:45 -08:00
+++edited/include/asm-sparc64/compat.h2005-02-07 19:51:15 -08:00
Review line 140
Quoted 8 lines
(quoted diff) +2
-0@@ -133,6 +133,8 @@ if (!(test_thread_flag(TIF_32BIT))) usp += STACK_BIAS; + else + usp &= 0xffffffffUL; return (void __user *) (usp - len); }
Hi Dave,
This patch takes care of the problem nicely (ypbind/ypwhich no longer hangs and ifconfig works fine). Thanks a lot for quick fixes.
Best regards
Jurij Smakov [email protected]
Key: http://www.wooyd.org/pgpkey/ KeyID: C99E03CC
Dear listmembers,
seing the communication between Jurij and Dave I took a glance into the 2.4.29 - tree and found the identical code segment as discussed below. This tells me that 2.4.X is supposed to suffer from the same issues as you tracked down for 2.6.X, isn't it? However, what I did not find is include/asm-sparc64/compat.h; this made me wonder whether I should expect a basic difference here, but maybe I simply misunderstood. Thanks,
take care
Dieter Jurzitza
-----Original Message-----
From: [email protected] [mailto:[email protected]]On Behalf Of David S. Miller
Sent: Monday, February 07, 2005 8:58 PM
To: [email protected]
Cc: [email protected]
Subject: Re: Hang in SIOCGIFCONF ioctl handler
Quoted 5 lines · On Mon, 7 Feb 2005 13:21:16 -0500 (EST) Jurij Smakov <[email protected]> wrote:
On an unrelated note, during my exploration I came across the function
copy_in_user_fixupinarch/sparc64/lib/user_fixup.c. In this function (and in other functions in that file) copying is done using a loop like this:while(size--) {
****
*******************************************
Diese E-Mail enthaelt vertrauliche und/oder rechtlich geschuetzte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtuemlich erhalten haben, informieren Sie bitte sofort den Absender und loeschen Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet.
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the contents in this e-mail is strictly forbidden.
*******************************************
Quoted 1 line · Dieter
seing the communication between Jurij and Dave I took a glance into the 2.4.29 - tree and found the identical code segment as discussed below. This tells me that 2.4.X is supposed to suffer from the same issues as you tracked down for 2.6.X, isn't it? However, what I did not find is
include/asm-sparc64/compat.h; this made me wonder whether I should expect a basic difference here, but maybe I simply misunderstood.
It's in arch/sparc64/kernel/ioctl32.c and arch/sparc64/kernel/sys_sparc32.c and I've already fixed it in my local tree which will push over to Marcelo soon.