linux-user: NETLINK_LIST_MEMBERSHIPS: Allow bad ptr if its length is 0
PATCH 1/1 linux-user: NETLINK_LIST_MEMBERSHIPS: Allow bad ptr if its length is 0
getsockopt(fd, SOL_NETLINK, NETLINK_LIST_MEMBERSHIPS, *optval, *optlen) syscall allows optval to be NULL/invalid if optlen points to a size of zero. This allows userspace to query the length of the array they should use to get the full membership list before allocating memory for said list, then re-calling getsockopt with proper optval/optlen arguments.
Notable users of this pattern include systemd-networkd, which in the (albeit old) version 237 tested, cannot start without this fix.
--- linux-user/syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/syscall.c +1 -1
@@ -3025,7 +3025,7 @@ get_timeout:return -TARGET_EINVAL ; } results =lock_user (VERIFY_WRITE , optval_addr, len,1 ); -if (!results) { +if (!results && len >0 ) {return -TARGET_EFAULT ; } lv = len;
Signature · 1 line
2.25.1
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [PATCH] linux-user: NETLINK_LIST_MEMBERSHIPS: Allow bad ptr if its length is 0
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
e2ba7fb linux-user: NETLINK_LIST_MEMBERSHIPS: Allow bad ptr if its length is 0
=== OUTPUT BEGIN ===
ERROR: Author email address is mangled by the mailing list #2:
Author: Frédéric Fortier via <[email protected]>
total: 1 errors, 0 warnings, 8 lines checked
Commit e2ba7fbd7535 (linux-user: NETLINK_LIST_MEMBERSHIPS: Allow bad ptr if its length is 0) has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Le 28/03/2021 à 20:01, Frédéric Fortier via a écrit :
Quoted 20 lines
getsockopt(fd, SOL_NETLINK, NETLINK_LIST_MEMBERSHIPS, *optval, *optlen)syscall allows optval to be NULL/invalid if optlen points to a size of zero. This allows userspace to query the length of the array they should use to get the full membership list before allocating memory for said list, then re-calling getsockopt with proper optval/optlen arguments.Notable users of this pattern include systemd-networkd, which in the (albeit old) version 237 tested, cannot start without this fix.
Signed-off-by Frédéric Fortier <[email protected]>--- linux-user/syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)linux-user/syscall.c +0
-0
linux-user/syscall.c get_timeout: · line 3031
Quoted 8 lines
linux-user/syscall.c +1
-1@@ -3025,7 +3025,7 @@ get_timeout:return -TARGET_EINVAL ; } results =lock_user (VERIFY_WRITE , optval_addr, len,1 ); -if (!results) { +if (!results && len >0 ) {return -TARGET_EFAULT ; } lv = len;
Laurent Vivier
AppliedLe 28/03/2021 à 20:01, Frédéric Fortier via a écrit :
Quoted 20 lines
getsockopt(fd, SOL_NETLINK, NETLINK_LIST_MEMBERSHIPS, *optval, *optlen)syscall allows optval to be NULL/invalid if optlen points to a size of zero. This allows userspace to query the length of the array they should use to get the full membership list before allocating memory for said list, then re-calling getsockopt with proper optval/optlen arguments.Notable users of this pattern include systemd-networkd, which in the (albeit old) version 237 tested, cannot start without this fix.
Signed-off-by Frédéric Fortier <[email protected]>--- linux-user/syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)linux-user/syscall.c +0
-0
linux-user/syscall.c get_timeout: · line 3031
Quoted 8 lines
linux-user/syscall.c +1
-1@@ -3025,7 +3025,7 @@ get_timeout:return -TARGET_EINVAL ; } results =lock_user (VERIFY_WRITE , optval_addr, len,1 ); -if (!results) { +if (!results && len >0 ) {return -TARGET_EFAULT ; } lv = len;
Applied to my linux-user-for-6.0 branch
Thanks,
Laurent