Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp14571012ybl; Mon, 30 Dec 2019 12:40:32 -0800 (PST) X-Google-Smtp-Source: APXvYqzaB9ZaVRKNimJjB8sEnycEFTmmt8X331m5ywCA3EXyk+ivzeoSHGCyKoQCtB/a6UCWX16h X-Received: by 2002:a9d:7f12:: with SMTP id j18mr79337324otq.17.1577738432839; Mon, 30 Dec 2019 12:40:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577738432; cv=none; d=google.com; s=arc-20160816; b=zwnePPgZmNYdoCk+jiTW7c2jUG2vvyePfBrjvzNhPaOY665T8NBnNsdmIclM8+QTgX 9W32oJH8qh3DdVafSv+gE960aKoqmtJEE/rqwEmEzhiWd8hJRNtrzLw0MFaMLXZIxq2z 94JgWFERGXuR5Svg+7LOKvaV2A1w3BvRywIWXtiWkDm2UbyIQaav2fTPlBqjY5HgwW3f B8pUIyK4ovYKZgEt//MURfvtv6v5T7nc54Lqy6rF6o/43vTMIjokyuHE/nMuG9x82MeZ OOOUJznwU6EpJB79ypcHU/aYzNg2vl4LH58K+Z+JOXUQkr0+mTjKKUy8xANv90/k6V82 MOSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=DCmfcVGhIPIEtkFz9D8Xp0Dnftdi6meO7YleSZubkbI=; b=scmN3wsWTiTnFbX44/OwmF9d1HannbusQsDrE7rAtVJmvco/oSFEEgcTvmg/PceG4F KFGtYQ9DYzSlSAOK66kG9lRzd6RDXMHoiuZbWlajyHzIj5Vcg8tpm/JZw4yER6TowdiX BEnC8yo6ZjKEqVV4qBN00TCJxhX7Vv5ENJ7bAzlFr3wF+r8TLdZGc8uAVunELxGaCTHN LXReVgFx/j7FMxlMYZPdwcOZ0oEPu8iIYTOuIaQ588VKjE8Hjdx/2DCG7rX33aDIGhML tfyNXlGZVjQ6RoVEGsj/tQ3SZyQeas+pU10sgMVYzjKp3SJ5YnpWAzSFMEWhcLhewX5D dF/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sargun.me header.s=google header.b=ROTOztYB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 13si15917846oiy.28.2019.12.30.12.40.21; Mon, 30 Dec 2019 12:40:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@sargun.me header.s=google header.b=ROTOztYB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727738AbfL3Ujd (ORCPT + 99 others); Mon, 30 Dec 2019 15:39:33 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:43514 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727691AbfL3Ujd (ORCPT ); Mon, 30 Dec 2019 15:39:33 -0500 Received: by mail-pg1-f196.google.com with SMTP id k197so18535603pga.10 for ; Mon, 30 Dec 2019 12:39:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sargun.me; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DCmfcVGhIPIEtkFz9D8Xp0Dnftdi6meO7YleSZubkbI=; b=ROTOztYBWpBZLGXNQrTL/Q0Qdb0/8c+RR6XLuTdo1KZU1Sk9qeVVj6JuAj1JZNA9v8 XkaK5I3NcPUIPdPLogpBJnJECO/wGtYZ1tTipYlEbPIJq58t+7+BQVpnB2kCaQzeva86 3DW9FwcAVtFRPw2mIPhyCCrtb/5ZG23dMDB3g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DCmfcVGhIPIEtkFz9D8Xp0Dnftdi6meO7YleSZubkbI=; b=ZNszu9QKPe8S4LnvD+NWLDBBblRkJPWUnlmjrR8PAZh5cQqgUbRKaAudoVXbIFmZgH szdvDKh6jNFTVYWbbU1YasOoja6PfN6Gow4xAPHhtB6qN67rilK+3JwQNDNiDJBt5jLU aD666apfgwqox9Es3oauZqmVZ2GOutYYtXATQjJUNDL2OGaIE+YQHskUnv12V14aRS8A FhUwqQn/dFcPO28wSwisvwjtstv6fEkj5JwEcLkaKluzhxjP0vnqGFo4ThyJLekINyio DSZnuqRKegugFKB4S+izK65wVL0FpCSeY2JehMzWqy3qmiHAI6LIpw7xLaygMqbcucuK Cf7Q== X-Gm-Message-State: APjAAAUi30qzX9LpkeUzgL/hEwpzYG32AHUseDV2i0rmRwLnDzCQ4ktg Jp3cDdc6GcHEwdb/liwg6CfQurxbBu4zyQ== X-Received: by 2002:aa7:9629:: with SMTP id r9mr40320076pfg.51.1577738372337; Mon, 30 Dec 2019 12:39:32 -0800 (PST) Received: from ubuntu.netflix.com (203.20.25.136.in-addr.arpa. [136.25.20.203]) by smtp.gmail.com with ESMTPSA id 11sm54053387pfz.25.2019.12.30.12.39.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2019 12:39:31 -0800 (PST) From: Sargun Dhillon To: LKML Cc: Christian Brauner , Aleksa Sarai , Tycho Andersen , Sargun Dhillon , Kees Cook Subject: [PATCH] selftests/seccomp: Test kernel catches garbage on SECCOMP_IOCTL_NOTIF_RECV Date: Mon, 30 Dec 2019 12:38:11 -0800 Message-Id: <20191230203811.4996-1-sargun@sargun.me> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds to the user_notification_basic to set a field of seccomp_notif to an invalid value to ensure that the kernel returns EINVAL if any of the seccomp_notif fields are set to invalid values. Signed-off-by: Sargun Dhillon Suggested-by: Christian Brauner Cc: Kees Cook --- tools/testing/selftests/seccomp/seccomp_bpf.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c index f53f14971bff..393578a78dbc 100644 --- a/tools/testing/selftests/seccomp/seccomp_bpf.c +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c @@ -3158,6 +3158,13 @@ TEST(user_notification_basic) EXPECT_GT(poll(&pollfd, 1, -1), 0); EXPECT_EQ(pollfd.revents, POLLIN); + /* Test that we can't pass garbage to the kernel. */ + memset(&req, 0, sizeof(req)); + req.pid = -1; + EXPECT_EQ(-1, ioctl(listener, SECCOMP_IOCTL_NOTIF_RECV, &req)); + EXPECT_EQ(EINVAL, errno); + + req.pid = 0; EXPECT_EQ(ioctl(listener, SECCOMP_IOCTL_NOTIF_RECV, &req), 0); pollfd.fd = listener; -- 2.20.1