All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] samples/seccomp: Zero out datastructures based on seccomp_notif_sizes
@ 2019-12-30 20:35 Sargun Dhillon
  2019-12-30 22:02 ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: Sargun Dhillon @ 2019-12-30 20:35 UTC (permalink / raw)
  To: LKML
  Cc: Christian Brauner, Aleksa Sarai, Sargun Dhillon, Tycho Andersen,
	Kees Cook

The sizes by which seccomp_notif and seccomp_notif_resp are allocated are
based on the SECCOMP_GET_NOTIF_SIZES ioctl. This allows for graceful
extension of these datastructures. If userspace zeroes out the
datastructure based on its version, and it is lagging behind the kernel's
version, it will end up sending trailing garbage. On the other hand,
if it is ahead of the kernel version, it will write extra zero space,
and potentially cause corruption.

Signed-off-by: Sargun Dhillon <sargun@sargun.me>
Suggested-by: Tycho Andersen <tycho@tycho.ws>
Cc: Kees Cook <keescook@chromium.org>
---
 samples/seccomp/user-trap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/samples/seccomp/user-trap.c b/samples/seccomp/user-trap.c
index 3e31ec0cf4a5..20291ec6489f 100644
--- a/samples/seccomp/user-trap.c
+++ b/samples/seccomp/user-trap.c
@@ -302,10 +302,10 @@ int main(void)
 		resp = malloc(sizes.seccomp_notif_resp);
 		if (!resp)
 			goto out_req;
-		memset(resp, 0, sizeof(*resp));
+		memset(resp, 0, sizes.seccomp_notif_resp);
 
 		while (1) {
-			memset(req, 0, sizeof(*req));
+			memset(req, 0, sizes.seccomp_notif);
 			if (ioctl(listener, SECCOMP_IOCTL_NOTIF_RECV, req)) {
 				perror("ioctl recv");
 				goto out_resp;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] samples/seccomp: Zero out datastructures based on seccomp_notif_sizes
  2019-12-30 20:35 [PATCH] samples/seccomp: Zero out datastructures based on seccomp_notif_sizes Sargun Dhillon
@ 2019-12-30 22:02 ` Kees Cook
  0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2019-12-30 22:02 UTC (permalink / raw)
  To: Sargun Dhillon; +Cc: LKML, Christian Brauner, Aleksa Sarai, Tycho Andersen

On Mon, Dec 30, 2019 at 12:35:03PM -0800, Sargun Dhillon wrote:
> The sizes by which seccomp_notif and seccomp_notif_resp are allocated are
> based on the SECCOMP_GET_NOTIF_SIZES ioctl. This allows for graceful
> extension of these datastructures. If userspace zeroes out the
> datastructure based on its version, and it is lagging behind the kernel's
> version, it will end up sending trailing garbage. On the other hand,
> if it is ahead of the kernel version, it will write extra zero space,
> and potentially cause corruption.
> 
> Signed-off-by: Sargun Dhillon <sargun@sargun.me>
> Suggested-by: Tycho Andersen <tycho@tycho.ws>
> Cc: Kees Cook <keescook@chromium.org>

Ah, cool. I've rearranged things and split the other patch's samples
changes into this one, etc etc :)

Thanks!

-Kees

> ---
>  samples/seccomp/user-trap.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/samples/seccomp/user-trap.c b/samples/seccomp/user-trap.c
> index 3e31ec0cf4a5..20291ec6489f 100644
> --- a/samples/seccomp/user-trap.c
> +++ b/samples/seccomp/user-trap.c
> @@ -302,10 +302,10 @@ int main(void)
>  		resp = malloc(sizes.seccomp_notif_resp);
>  		if (!resp)
>  			goto out_req;
> -		memset(resp, 0, sizeof(*resp));
> +		memset(resp, 0, sizes.seccomp_notif_resp);
>  
>  		while (1) {
> -			memset(req, 0, sizeof(*req));
> +			memset(req, 0, sizes.seccomp_notif);
>  			if (ioctl(listener, SECCOMP_IOCTL_NOTIF_RECV, req)) {
>  				perror("ioctl recv");
>  				goto out_resp;
> -- 
> 2.20.1
> 

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-12-30 22:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-30 20:35 [PATCH] samples/seccomp: Zero out datastructures based on seccomp_notif_sizes Sargun Dhillon
2019-12-30 22:02 ` Kees Cook

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.