Skip to contentSkip to conversation

Errenous use of memset and memcpy

PATCH In review Alexander Nyberg 4 participants 5 messages Feb 19, 2005 – Mar 3, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Errenous use of memset and memcpy

I stumbled across this, looks weird. Presumable fix is:

=== arch/ia64/ia32/ia32_signal.c 1.35 vs edited ==--- 1.35/arch/ia64/ia32/ia32_signal.c 2005-01-25 21:23:45 +01:00
+++ edited/arch/ia64/ia32/ia32_signal.c 2005-02-12 13:12:25 +01:00
@@ -460,10 +460,9 @@ __ia32_rt_sigsuspend (compat_sigset_t *s
sigset_t oldset, set;

scr->scratch_unat = 0; /* avoid leaking kernel bits to user level */
- memset(&set, 0, sizeof(&set));
+ memset(&set, 0, sizeof(sigset_t));

- if (memcpy(&set.sig, &sset->sig, sigsetsize))
- return -EFAULT;
+ memcpy(&set.sig, &sset->sig, sigsetsize);

sigdelsetmask(&set, ~_BLOCKABLE);

#1 lore raw
Quoted 5 lines · Alexander Nyberg

I stumbled across this, looks weird. Presumable fix is:

=== arch/ia64/ia32/ia32_signal.c 1.35 vs edited ==> --- 1.35/arch/ia64/ia32/ia32_signal.c 2005-01-25 21:23:45 +01:00
+++ edited/arch/ia64/ia32/ia32_signal.c 2005-02-12 13:12:25 +01:00

Review __ia32_rt_sigsuspend (compat_sigset_t *s · line 465

Quoted 9 lines
(quoted diff) +2 -3
@@ -460,10 +460,9 @@ __ia32_rt_sigsuspend (compat_sigset_t *s
 	sigset_t oldset, set;
 
 	scr->scratch_unat = 0;	/* avoid leaking kernel bits to user level */
-	memset(&set, 0, sizeof(&set));
+	memset(&set, 0, sizeof(sigset_t));
 
-	if (memcpy(&set.sig, &sset->sig, sigsetsize))
-		return -EFAULT;
+	memcpy(&set.sig, &sset->sig, sigsetsize);

That should be copy_from_user, and the error checking needs to stay.

Andreas.

Signature · 4 lines
Andreas Schwab, SuSE Labs, [email protected]
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
#2 lore raw
In reply to Alexander Nyberg
Quoted 2 lines

That should be copy_from_user, and the error checking needs to stay.

Makes sense, thanks.

=== arch/ia64/ia32/ia32_signal.c 1.35 vs edited ==--- 1.35/arch/ia64/ia32/ia32_signal.c 2005-01-25 21:23:45 +01:00
+++ edited/arch/ia64/ia32/ia32_signal.c 2005-02-20 11:32:55 +01:00
@@ -460,9 +460,9 @@ __ia32_rt_sigsuspend (compat_sigset_t *s
sigset_t oldset, set;

scr->scratch_unat = 0; /* avoid leaking kernel bits to user level */
- memset(&set, 0, sizeof(&set));
+ memset(&set, 0, sizeof(sigset_t));

- if (memcpy(&set.sig, &sset->sig, sigsetsize))
+ if (copy_from_user(&set.sig, &sset->sig, sigsetsize))
return -EFAULT;

sigdelsetmask(&set, ~_BLOCKABLE);

#3 lore raw
In reply to Alexander Nyberg

Review __ia32_rt_sigsuspend (compat_sigset_t *s · line 463

Quoted 8 lines · Alexander Nyberg

=== arch/ia64/ia32/ia32_signal.c 1.35 vs edited ==> --- 1.35/arch/ia64/ia32/ia32_signal.c 2005-01-25 21:23:45 +01:00
+++ edited/arch/ia64/ia32/ia32_signal.c 2005-02-20 11:32:55 +01:00

(quoted diff) +1 -1
@@ -460,9 +460,9 @@ __ia32_rt_sigsuspend (compat_sigset_t *s
 	sigset_t oldset, set;
 
 	scr->scratch_unat = 0;	/* avoid leaking kernel bits to user level */
-	memset(&set, 0, sizeof(&set));
+	memset(&set, 0, sizeof(sigset_t));

To check that the above is correct, you have to go look up the declaration of "set". Why not do this:

+ memset(&set, 0, sizeof(set));

which is clearly correct, regardless of the declaration?

#4 lore raw
In reply to Alexander Nyberg
Quoted 16 lines · Bjorn Helgaas

arch/ia64/ia32/ia32_signal.c __ia32_rt_sigsuspend (compat_sigset_t *s · line 463

Quoted 9 lines · Alexander Nyberg

===== arch/ia64/ia32/ia32_signal.c 1.35 vs edited =====

arch/ia64/ia32/ia32_signal.c +1 -1
@@ -460,9 +460,9 @@ __ia32_rt_sigsuspend (compat_sigset_t *s
 	sigset_t oldset, set;
 
 	scr->scratch_unat = 0;	/* avoid leaking kernel bits to user level */
-	memset(&set, 0, sizeof(&set));
+	memset(&set, 0, sizeof(sigset_t));

To check that the above is correct, you have to go look up the declaration of "set". Why not do this:

(quoted diff) +1 -0
+	memset(&set, 0, sizeof(set));
Quoted 2 lines

which is clearly correct, regardless of the declaration?

Agree and I think memcpy is just fine. Tony, please apply the attached patch.

-Arun

- Fix the incorrect argument to sizeof()
- memcpy should always succeed because it's a kernel space to kernel space copy.

arch/ia64/ia32/ia32_signal.c +2 -3
@@ -460,10 +460,9 @@
 	sigset_t oldset, set;
 
 	scr->scratch_unat = 0;	/* avoid leaking kernel bits to user level */
-	memset(&set, 0, sizeof(&set));
+	memset(&set, 0, sizeof(set));
 
-	if (memcpy(&set.sig, &sset->sig, sigsetsize))
-		return -EFAULT;
+	memcpy(&set.sig, &sset->sig, sigsetsize);
 
 	sigdelsetmask(&set, ~_BLOCKABLE);