Skip to contentSkip to conversation

kernel/sys.c: fix prctl_set_auxv to use sizeof instead of user-supplied len

PATCH In review Aiden Bowling 4 participants 5 messages Jun 2 – Jun 3 1 message not in the archive Stable branch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel/sys.c: fix prctl_set_auxv to use sizeof instead of user-supplied len

prctl_set_auxv() passed the user-supplied 'len' to memcpy() when copying into mm->saved_auxv, instead of sizeof(user_auxv). Since user_auxv is already sized to the full auxv buffer, using 'len' risks a partial write if the caller supplies a smaller value. Use sizeof(user_auxv) to always copy the full buffer after validation.

---
 kernel/sys.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sys.c +1 -1
index 62e842055cc9..d3f5229649e3 100644
@@ -2189,7 +2189,7 @@ static int prctl_set_auxv(struct mm_struct *mm, unsigned long addr,
 	BUILD_BUG_ON(sizeof(user_auxv) != sizeof(mm->saved_auxv));
 
 	task_lock(current);
-	memcpy(mm->saved_auxv, user_auxv, len);
+	memcpy(mm->saved_auxv, user_auxv, sizeof(user_auxv));
 	task_unlock(current);
 
 	return 0;

base-commit: e43ffb69e0438cddd72aaa30898b4dc446f664f8

Signature · 1 line
2.54.0
#1 lore raw
Quoted 5 lines · On Mon, 1 Jun 2026 22:40:02 -0400 Aiden Bowling <[email protected]>…

prctl_set_auxv() passed the user-supplied 'len' to memcpy() when copying into mm->saved_auxv, instead of sizeof(user_auxv). Since user_auxv is already sized to the full auxv buffer, using 'len' risks a partial write if the caller supplies a smaller value. Use sizeof(user_auxv) to always copy the full buffer after validation.

Is it possibly that the caller only wants to write the first few values?

-- David

Quoted 21 lines
---
 kernel/sys.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sys.c +1 -1
index 62e842055cc9..d3f5229649e3 100644
@@ -2189,7 +2189,7 @@ static int prctl_set_auxv(struct mm_struct *mm, unsigned long addr,
 	BUILD_BUG_ON(sizeof(user_auxv) != sizeof(mm->saved_auxv));
 
 	task_lock(current);
-	memcpy(mm->saved_auxv, user_auxv, len);
+	memcpy(mm->saved_auxv, user_auxv, sizeof(user_auxv));
 	task_unlock(current);
 
 	return 0;

base-commit: e43ffb69e0438cddd72aaa30898b4dc446f664f8

#2 lore raw
In reply to Aiden Bowling
Quoted 5 lines · Aiden Bowling

prctl_set_auxv() passed the user-supplied 'len' to memcpy() when copying into mm->saved_auxv, instead of sizeof(user_auxv). Since user_auxv is already sized to the full auxv buffer, using 'len' risks a partial write if the caller supplies a smaller value. Use sizeof(user_auxv) to always copy the full buffer after validation.

Hm, but would this be an issue? A user can specify only a partial write and get what they expect, I don't think there's any security issue here.

I also guess a user could specify a length that's not a multiple of sizeof(unsigned long) but again they'd get the results they might expect from doing something silly like that :)

And users might rely on this only doing a partial write for whatever weird reason so I don't think we can change this really?

Quoted 20 lines
---
 kernel/sys.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sys.c +1 -1
index 62e842055cc9..d3f5229649e3 100644
@@ -2189,7 +2189,7 @@ static int prctl_set_auxv(struct mm_struct *mm, unsigned long addr,
 	BUILD_BUG_ON(sizeof(user_auxv) != sizeof(mm->saved_auxv));
 
 	task_lock(current);
-	memcpy(mm->saved_auxv, user_auxv, len);
+	memcpy(mm->saved_auxv, user_auxv, sizeof(user_auxv));
 	task_unlock(current);
 
 	return 0;
Quoted 4 lines

base-commit: e43ffb69e0438cddd72aaa30898b4dc446f664f8 --
2.54.0

Cheers, Lorenzo

A message that is not in the archive (sent off-list or not yet received): CAGOa741UNr5DzK4vr8RBLvhZcCs9zdva6tqmMptQw5P8ooNEOA@mail.gmail.com

#4 lore raw
Quoted 5 lines · Aiden Bowling

The issue is that using the user-supplied 'len' risks a partial write into mm-

Quoted 1 line

saved_auxv if they pass something smaller than the actual buffer size, even if

the buffer is validated. We should always copy the full buffer size after validation to maintain consistency and prevent accidental partial data exposure/ corruption.

Which partial data exposure?

Signature · 3 lines
Cheers,

David
#5 lore raw
Quoted 9 lines · On Tue, 2 Jun 2026 19:25:56 +0200 "David Hildenbrand (Arm)" <[email protected]>…
Quoted 5 lines · Aiden Bowling

The issue is that using the user-supplied 'len' risks a partial write into mm-

Quoted 1 line

saved_auxv if they pass something smaller than the actual buffer size, even if

the buffer is validated. We should always copy the full buffer size after validation to maintain consistency and prevent accidental partial data exposure/ corruption.

Which partial data exposure?

The one you don't get with the patch because of the previously unnecessary initialisation of the array :-)