Fix Warnining in arch/x86/kernel/signal.c
PATCH 1/1 Fix Warnining in arch/x86/kernel/signal.c
Hi,
Quoted 8 lines · Andi Kleen
On Tue, May 12, 2009 at 05:16:14PM +0530, Subrata Modak wrote:
Hi Subrata,
Quoted 2 lines
With gcc (GCC) 4.4.1 20090429 (prerelease), i get the following build warning:
Quoted 8 lines
Patch looks good (you can add a
Reviewed-by Andi Kleen <[email protected]>)But I don't maintain this code anymore. Please resend to [email protected] cc [email protected] for merge.
Thanks,
-Andi
With gcc (GCC) 4.4.1 20090429 (prerelease), i get the following build warning:
CC arch/x86/kernel/signal.oarch/x86/kernel/signal.c: In function ‘sys_sigreturn’:arch/x86/kernel/signal.c:573: warning: ‘set.sig[1]’ may be used uninitialized in this function
On investigation i found that this is because of the evaluation precedence of the expression below:
569 unsigned long sys_sigreturn(struct pt_regs *regs) 570 {
571 struct sigframe __user *frame; 572 unsigned long ax; 573 sigset_t set;
574
575 frame = (struct sigframe __user *)(regs->sp - 8);
576
577 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
578 goto badframe;
579 if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1
580 && __copy_from_user(&set.sig[1], &frame->extramask,
581 sizeof(frame->extramask))))
The initialization for set.sig[1] may not occur if
__get_user(set.sig[0], &frame->sc.oldmask)
evalutes to true. So, the compiler is complaining.
I have devised a small patch for this which wanes away this warning without changing the conditional evaluation criteria. Let me know if you like this patch.
582 goto badframe;
583
584 sigdelsetmask(&set, ~_BLOCKABLE); 585 spin_lock_irq(¤t->sighand->siglock); 586 current->blocked = set; 587 recalc_sigpending(); 588 spin_unlock_irq(¤t->sighand->siglock);
589
590 if (restore_sigcontext(regs, &frame->sc, &ax))
591 goto badframe;
592 return ax;
593
594 badframe:
595 signal_fault(regs, frame, "sigreturn");
596
597 return 0;
598 }
To: <[email protected]>
Cc: Linux Kernel <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Balbir Singh <[email protected]>
Cc: Sachin P Sant <[email protected]>
Subject: [PATCH] Fix Warnining in arch/x86/kernel/signal.c
---
arch/x86/kernel/signal.c +4 -3
@@ -576,9 +576,10 @@ unsigned long sys_sigreturn(struct pt_reif (!access_ok (VERIFY_READ , frame,sizeof (*frame))) goto badframe; -if (__get_user (set.sig[0 ], &frame->sc.oldmask) || (_NSIG_WORDS >1 - &&__copy_from_user (&set.sig[1 ], &frame->extramask, -sizeof (frame->extramask)))) + +if ( (__copy_from_user (&set.sig[1 ], &frame->extramask, +sizeof (frame->extramask)) && _NSIG_WORDS >1 ) || +__get_user (set.sig[0 ], &frame->sc.oldmask)) goto badframe;sigdelsetmask (&set, ~_BLOCKABLE);
---
Regards--
Subrata
Quoted 82 lines · Subrata Modak
Hi,
Quoted 6 lines · Andi Kleen
On Tue, May 12, 2009 at 05:16:14PM +0530, Subrata Modak wrote:
Hi Subrata,
Quoted 1 line
With gcc (GCC) 4.4.1 20090429 (prerelease), i get the following build warning:
Quoted 8 lines
Patch looks good (you can add a
Reviewed-by Andi Kleen <[email protected]>)But I don't maintain this code anymore. Please resend to [email protected] cc [email protected] for merge.
Thanks,
-Andi
With gcc (GCC) 4.4.1 20090429 (prerelease), i get the following build warning:
CC
arch/x86/kernel/signal.oarch/x86/kernel/signal.c: In function ‘sys_sigreturn’:arch/x86/kernel/signal.c:573: warning: ‘set.sig[1]’ may be used uninitialized in this functionOn investigation i found that this is because of the evaluation precedence of the expression below:
569 unsigned long
sys_sigreturn(struct pt_regs *regs)570 {571 struct sigframe __user *frame; 572 unsigned long ax; 573 sigset_t set;574
575 frame = (struct sigframe__user*)(regs->sp - 8);
576
577 if (!access_ok(VERIFY_READ, frame,sizeof(*frame)))
578 goto badframe;
579 if (__get_user(set.sig[0], &frame->sc.oldmask)|| (_NSIG_WORDS> 1
580 && __copy_from_user(&set.sig[1],&frame->extramask,
581sizeof(frame->extramask))))The initialization for set.sig[1] may not occur if
__get_user(set.sig[0], &frame->sc.oldmask)evalutes to true. So, the compiler is complaining.
I have devised a small patch for this which wanes away this warning without changing the conditional evaluation criteria. Let me know if you like this patch.
582 goto badframe;
583584 sigdelsetmask(&set, ~_BLOCKABLE); 585 spin_lock_irq(¤t->sighand->siglock); 586 current->blocked = set; 587 recalc_sigpending(); 588 spin_unlock_irq(¤t->sighand->siglock);589
590 if (restore_sigcontext(regs, &frame->sc, &ax))
591 goto badframe;
592 return ax;
593
594 badframe:
595signal_fault(regs, frame, "sigreturn");
596
597 return 0;
598 }Signed-off-by Subrata Modak <[email protected]>Reviewed-by Andi Kleen <[email protected]>To: <[email protected]>
Cc: Linux Kernel <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Balbir Singh <[email protected]>
Cc: Sachin P Sant <[email protected]>
Subject: [PATCH] Fix Warnining inarch/x86/kernel/signal.c
---arch/x86/kernel/signal.c +0
-0@@ -576,9 +576,10 @@ unsigned long sys_sigreturn(struct pt_re
arch/x86/kernel/signal.c unsigned long sys_sigreturn(struct pt_re · line 583
Quoted 10 lines
arch/x86/kernel/signal.c +4
-3if (!access_ok (VERIFY_READ , frame,sizeof (*frame))) goto badframe; -if (__get_user (set.sig[0 ], &frame->sc.oldmask) || (_NSIG_WORDS >1 - &&__copy_from_user (&set.sig[1 ], &frame->extramask, -sizeof (frame->extramask)))) + +if ( (__copy_from_user (&set.sig[1 ], &frame->extramask, +sizeof (frame->extramask)) && _NSIG_WORDS >1 ) || +__get_user (set.sig[0 ], &frame->sc.oldmask)) goto badframe;
I'm not sure why this eliminates that warning.
set.sig[0] may not be initialized too, if __copy_from_user() failed. I don't have enough time to look at this right now, sorry.
Another question, __copy_from_user() will be called even if _NSIG_WORDS is less than 2, perhaps it never occurs.
I think, to check _NSIG_WORDS > 1 before calling __copy_from_user() is better.
Thanks,
Hiroshi
Quoted 83 lines · Hiroshi Shimamoto
Quoted 82 lines · Subrata Modak
Hi,
Quoted 6 lines · Andi Kleen
On Tue, May 12, 2009 at 05:16:14PM +0530, Subrata Modak wrote:
Hi Subrata,
Quoted 1 line
With gcc (GCC) 4.4.1 20090429 (prerelease), i get the following build warning:
Quoted 8 lines
Patch looks good (you can add a
Reviewed-by Andi Kleen <[email protected]>)But I don't maintain this code anymore. Please resend to [email protected] cc [email protected] for merge.
Thanks,
-Andi
With gcc (GCC) 4.4.1 20090429 (prerelease), i get the following build warning:
CC
arch/x86/kernel/signal.oarch/x86/kernel/signal.c: In function ‘sys_sigreturn’:arch/x86/kernel/signal.c:573: warning: ‘set.sig[1]’ may be used uninitialized in this functionOn investigation i found that this is because of the evaluation precedence of the expression below:
569 unsigned long
sys_sigreturn(struct pt_regs *regs)570 {571 struct sigframe __user *frame; 572 unsigned long ax; 573 sigset_t set;574
575 frame = (struct sigframe__user*)(regs->sp - 8);
576
577 if (!access_ok(VERIFY_READ, frame,sizeof(*frame)))
578 goto badframe;
579 if (__get_user(set.sig[0], &frame->sc.oldmask)|| (_NSIG_WORDS> 1
580 && __copy_from_user(&set.sig[1],&frame->extramask,
581sizeof(frame->extramask))))The initialization for set.sig[1] may not occur if
__get_user(set.sig[0], &frame->sc.oldmask)evalutes to true. So, the compiler is complaining.
I have devised a small patch for this which wanes away this warning without changing the conditional evaluation criteria. Let me know if you like this patch.
582 goto badframe;
583584 sigdelsetmask(&set, ~_BLOCKABLE); 585 spin_lock_irq(¤t->sighand->siglock); 586 current->blocked = set; 587 recalc_sigpending(); 588 spin_unlock_irq(¤t->sighand->siglock);589
590 if (restore_sigcontext(regs, &frame->sc, &ax))
591 goto badframe;
592 return ax;
593
594 badframe:
595signal_fault(regs, frame, "sigreturn");
596
597 return 0;
598 }Signed-off-by Subrata Modak <[email protected]>Reviewed-by Andi Kleen <[email protected]>To: <[email protected]>
Cc: Linux Kernel <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Balbir Singh <[email protected]>
Cc: Sachin P Sant <[email protected]>
Subject: [PATCH] Fix Warnining inarch/x86/kernel/signal.c
---arch/x86/kernel/signal.c +0
-0@@ -576,9 +576,10 @@ unsigned long sys_sigreturn(struct pt_re
Quoted 13 lines
arch/x86/kernel/signal.c unsigned long sys_sigreturn(struct pt_re · line 583
Quoted 10 lines
arch/x86/kernel/signal.c +4
-3if (!access_ok (VERIFY_READ , frame,sizeof (*frame))) goto badframe; -if (__get_user (set.sig[0 ], &frame->sc.oldmask) || (_NSIG_WORDS >1 - &&__copy_from_user (&set.sig[1 ], &frame->extramask, -sizeof (frame->extramask)))) + +if ( (__copy_from_user (&set.sig[1 ], &frame->extramask, +sizeof (frame->extramask)) && _NSIG_WORDS >1 ) || +__get_user (set.sig[0 ], &frame->sc.oldmask)) goto badframe;I'm not sure why this eliminates that warning.
set.sig[0] may not be initialized too, if__copy_from_user()failed.
True, but only when either or both of __copy_from_user() and (_NSIG_WORDS > 1) fails. But in all instances set.sig[1] gets initialized.
Quoted 6 lines
I don't have enough time to look at this right now, sorry.
Another question,
__copy_from_user()will be called even if_NSIG_WORDSis less than 2, perhaps it never occurs.
I think, to check_NSIG_WORDS> 1 before calling__copy_from_user()is better.
Fine. Let Ingo/Thomas/Peter decide whether they would like this fix or drop it.
Regards--
Subrata
Quoted 4 lines
Thanks,
Hiroshi
Quoted 104 lines · Subrata Modak
Quoted 83 lines · Hiroshi Shimamoto
Quoted 82 lines · Subrata Modak
Hi,
Quoted 6 lines · Andi Kleen
On Tue, May 12, 2009 at 05:16:14PM +0530, Subrata Modak wrote:
Hi Subrata,
Quoted 1 line
With gcc (GCC) 4.4.1 20090429 (prerelease), i get the following build warning:
Quoted 8 lines
Patch looks good (you can add a
Reviewed-by Andi Kleen <[email protected]>)But I don't maintain this code anymore. Please resend to [email protected] cc [email protected] for merge.
Thanks,
-Andi
With gcc (GCC) 4.4.1 20090429 (prerelease), i get the following build warning:
CC
arch/x86/kernel/signal.oarch/x86/kernel/signal.c: In function ‘sys_sigreturn’:arch/x86/kernel/signal.c:573: warning: ‘set.sig[1]’ may be used uninitialized in this functionOn investigation i found that this is because of the evaluation precedence of the expression below:
569 unsigned long
sys_sigreturn(struct pt_regs *regs)570 {571 struct sigframe __user *frame; 572 unsigned long ax; 573 sigset_t set;574
575 frame = (struct sigframe__user*)(regs->sp - 8);
576
577 if (!access_ok(VERIFY_READ, frame,sizeof(*frame)))
578 goto badframe;
579 if (__get_user(set.sig[0], &frame->sc.oldmask)|| (_NSIG_WORDS> 1
580 && __copy_from_user(&set.sig[1],&frame->extramask,
581sizeof(frame->extramask))))The initialization for set.sig[1] may not occur if
__get_user(set.sig[0], &frame->sc.oldmask)evalutes to true. So, the compiler is complaining.
I have devised a small patch for this which wanes away this warning without changing the conditional evaluation criteria. Let me know if you like this patch.
582 goto badframe;
583584 sigdelsetmask(&set, ~_BLOCKABLE); 585 spin_lock_irq(¤t->sighand->siglock); 586 current->blocked = set; 587 recalc_sigpending(); 588 spin_unlock_irq(¤t->sighand->siglock);589
590 if (restore_sigcontext(regs, &frame->sc, &ax))
591 goto badframe;
592 return ax;
593
594 badframe:
595signal_fault(regs, frame, "sigreturn");
596
597 return 0;
598 }Signed-off-by Subrata Modak <[email protected]>Reviewed-by Andi Kleen <[email protected]>To: <[email protected]>
Cc: Linux Kernel <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Balbir Singh <[email protected]>
Cc: Sachin P Sant <[email protected]>
Subject: [PATCH] Fix Warnining inarch/x86/kernel/signal.c
---arch/x86/kernel/signal.c +0
-0@@ -576,9 +576,10 @@ unsigned long sys_sigreturn(struct pt_reQuoted 13 lines
arch/x86/kernel/signal.c unsigned long sys_sigreturn(struct pt_re · line 583
Quoted 10 lines
arch/x86/kernel/signal.c +4
-3if (!access_ok (VERIFY_READ , frame,sizeof (*frame))) goto badframe; -if (__get_user (set.sig[0 ], &frame->sc.oldmask) || (_NSIG_WORDS >1 - &&__copy_from_user (&set.sig[1 ], &frame->extramask, -sizeof (frame->extramask)))) + +if ( (__copy_from_user (&set.sig[1 ], &frame->extramask, +sizeof (frame->extramask)) && _NSIG_WORDS >1 ) || +__get_user (set.sig[0 ], &frame->sc.oldmask)) goto badframe;I'm not sure why this eliminates that warning.
set.sig[0] may not be initialized too, if__copy_from_user()failed.True, but only when either or both of
__copy_from_user()and (_NSIG_WORDS> 1) fails. But in all instances set.sig[1] gets initialized.Quoted 2 lines
I don't have enough time to look at this right now, sorry.
Quoted 7 lines
Quoted 4 lines
Another question,
__copy_from_user()will be called even if_NSIG_WORDSis less than 2, perhaps it never occurs.
I think, to check_NSIG_WORDS> 1 before calling__copy_from_user()is better.Fine. Let Ingo/Thomas/Peter decide whether they would like this fix or drop it.
If you get the Acked-by from Hiroshi-san it looks good to me. He modified this code last.
Ingo
H. Peter Anvin
reviewerQuoted 23 lines · Ingo Molnar
Quoted 23 lines
Quoted 13 lines
arch/x86/kernel/signal.c unsigned long sys_sigreturn(struct pt_re · line 583
Quoted 11 lines
arch/x86/kernel/signal.c +4
-3if (!access_ok (VERIFY_READ , frame,sizeof (*frame))) goto badframe; -if (__get_user (set.sig[0 ], &frame->sc.oldmask) || (_NSIG_WORDS >1 - &&__copy_from_user (&set.sig[1 ], &frame->extramask, -sizeof (frame->extramask)))) + +if ( (__copy_from_user (&set.sig[1 ], &frame->extramask, +sizeof (frame->extramask)) && _NSIG_WORDS >1 ) || +__get_user (set.sig[0 ], &frame->sc.oldmask)) goto badframe;I'm not sure why this eliminates that warning.
set.sig[0] may not be initialized too, if__copy_from_user()failed.True, but only when either or both of
__copy_from_user()and (_NSIG_WORDS> 1) fails. But in all instances set.sig[1] gets initialized.Quoted 6 lines
I don't have enough time to look at this right now, sorry.
Another question,
__copy_from_user()will be called even if_NSIG_WORDSis less than 2, perhaps it never occurs.
I think, to check_NSIG_WORDS> 1 before calling__copy_from_user()is better.
Quoted 6 lines
Quoted 2 lines
Fine. Let Ingo/Thomas/Peter decide whether they would like this fix or drop it.
If you get the Acked-by from Hiroshi-san it looks good to me. He modified this code last.
This seriously looks wrong to me. If _NSIG_WORDS == 1, then calling __copy_from_user here is a serious error.
-hpa
Quoted 24 lines · H. Peter Anvin
Quoted 23 lines · Ingo Molnar
Quoted 23 lines
Quoted 13 lines
arch/x86/kernel/signal.c unsigned long sys_sigreturn(struct pt_re · line 583
Quoted 11 lines
arch/x86/kernel/signal.c +4
-3if (!access_ok (VERIFY_READ , frame,sizeof (*frame))) goto badframe; -if (__get_user (set.sig[0 ], &frame->sc.oldmask) || (_NSIG_WORDS >1 - &&__copy_from_user (&set.sig[1 ], &frame->extramask, -sizeof (frame->extramask)))) + +if ( (__copy_from_user (&set.sig[1 ], &frame->extramask, +sizeof (frame->extramask)) && _NSIG_WORDS >1 ) || +__get_user (set.sig[0 ], &frame->sc.oldmask)) goto badframe;I'm not sure why this eliminates that warning.
set.sig[0] may not be initialized too, if__copy_from_user()failed.True, but only when either or both of
__copy_from_user()and (_NSIG_WORDS> 1) fails. But in all instances set.sig[1] gets initialized.Quoted 6 lines
I don't have enough time to look at this right now, sorry.
Another question,
__copy_from_user()will be called even if_NSIG_WORDSis less than 2, perhaps it never occurs.
I think, to check_NSIG_WORDS> 1 before calling__copy_from_user()is better.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Fine. Let Ingo/Thomas/Peter decide whether they would like this fix or drop it.
If you get the Acked-by from Hiroshi-san it looks good to me. He modified this code last.
This seriously looks wrong to me. If
_NSIG_WORDS== 1, then calling__copy_from_userhere is a serious error.
Right. If _NSIG_WORDS is 1, sigset_t set has only sig[0], writing to set.sig[1] means stack corruption.
Subrata, could you try like this?
if ((_NSIG_WORDS > 1 && __copy_from_user(&set.sig[1], ...) ||
__get_user(set.sig[0], ...))
I wonder whether gcc really complains about the case of __get_user(set.sig[0], ...) failure.
Why, the case which sig[0] initialized and sig[1] uninitialized is NG and the case which sig[0] uninitialized and sig[1] initialized is OK.
Thanks,
Hiroshi