Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2838108imu; Sun, 9 Dec 2018 10:27:23 -0800 (PST) X-Google-Smtp-Source: AFSGD/X539lCcdoFAdA+n6pDYGL13/xXg+0CRBa6PuZrLyK3f7YvfV9yRO1FHaZzjLrBxR/k6lzU X-Received: by 2002:a17:902:d70b:: with SMTP id w11mr9537774ply.294.1544380043544; Sun, 09 Dec 2018 10:27:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544380043; cv=none; d=google.com; s=arc-20160816; b=Mj2Pd10kkB9Pdgvk20Q0KcIkWv0aUFv5FyXx01yRYyRz9Iks9IQyo5XH60k93g2i2d uVWPSqyqEJknvCFsH95zZWuTHfMIGICqQinniCAv2CZtUY/zAvuEntJP1SW6edkMq6nl Jm2kN5XPv8xpXfZeqzVgydEvLUEC5X/JWq4ReCrBYSuhDZFv+YOllvj5mIsKhVFTiv1r m/BlKVE4Akh0RXdSzgSprXreI23DyTA1yoCWhRyuEAqeNiaO/+SFWGxc43w5Np59G8Z/ VPm0ZMBrcvjtHcc4rHNgOnrRiHN176qU1lTElqpK8EpVQ8ZP68BzZHkBIMSAXXlahfAm QLZQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HkYVZ7daY1cwdpZ1lpCsOliAPs5GrROQtKSvKXGy2GM=; b=E2dcEWYX21UBYq2Q0PbDxTT6mFbtA5UrrKU7ZL4uuKRODbCgaRV6+DPa46/dSB1JmC 6dOBCM9VCp6NvDuy97PwD7D3Wd31IMbPV+HftfV+fFB7Fb8gUAyUPzUfFRyizszYwNll VuK7UTBVdAkywwG/v6jtyhXE/E6pdG6ppvLai1Zsopm0/J2sU99ni9tNJzh12jS0OQEk pK1a4Wqalby7OIokhMe1bfxvtwuMKwtzxE3/AhPq6Ow2zp+vD7K/AePcXARBK32/Z8R3 9XFMISLHoYWaRvA4uRfWYJSRGDJNoLK9nnjH2fQ0qkTu+FfOc71S4Yp+wwRDZQR3wc8j 6Hiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tycho-ws.20150623.gappssmtp.com header.s=20150623 header.b=UGVIzrSH; 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 w7si7014080ply.421.2018.12.09.10.27.08; Sun, 09 Dec 2018 10:27:23 -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=@tycho-ws.20150623.gappssmtp.com header.s=20150623 header.b=UGVIzrSH; 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 S1726246AbeLISY1 (ORCPT + 99 others); Sun, 9 Dec 2018 13:24:27 -0500 Received: from mail-io1-f66.google.com ([209.85.166.66]:38340 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726232AbeLISY0 (ORCPT ); Sun, 9 Dec 2018 13:24:26 -0500 Received: by mail-io1-f66.google.com with SMTP id l14so7060609ioj.5 for ; Sun, 09 Dec 2018 10:24:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tycho-ws.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HkYVZ7daY1cwdpZ1lpCsOliAPs5GrROQtKSvKXGy2GM=; b=UGVIzrSH9ntgbDzileq8k8GI7tP80Tb9h322c3V+dJncoUxyfyWG4g5vXy5rgwcJN+ +89ZwVsoNb280bq0wJ2uJEWQxjXsiR4UfiWolVxAruSUfyYtukBW0Iusp5v3ZLCdgKw/ jnyuD71JdP6wlHc/SlZYKLK3/s5VEj5VErCSjXRIdAyQehHF0m6JJnBBRg4tPRAywl8H MXx1hAybMtv91gQp+mlvhomFcbCsxiQyzdY0Kg/vWgK+r3w1e41IdBotud2oBKH3Y/Qs mbeFBVPPLUCDPxOnOEeMHnMTOmZPvHnzOlxZlpIzY2xvFf688JrFllc9Hh97q/Jj690M iEOA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=HkYVZ7daY1cwdpZ1lpCsOliAPs5GrROQtKSvKXGy2GM=; b=C3QonVEx0fpB8NDD6fv0QT79Wik8FOhsRNAMkrBZ2sKJVkfu0hqhA16eTvAgB94oW8 /glK8RCxqEfYP5oRaETVy0/eI4yKZuTu07YW34NE/TwaFkAVDvcDVyXdxDB4yeWXr/5e NDuDC+I8PgR9XDR6CMS8DejqNdQywDeByoKqO/eKjxayk6J98cZZOkTZGo2UZijTD0+C lxoV92phkYL8g7pWzPLu6gCiWrysgyveM94CvyLzr77EBgo8l0tuKN0L7CMRE9SUbwC/ bElKUmrCWDpA0I9oOFKadJLRIV0uYHS3L/g0WRRY2NZhmY9BaNCLFfRc4xL7kUwmmWAz z3JQ== X-Gm-Message-State: AA+aEWa+vQYVMaxKoXzQlxoEBdbymw24LbKUlvJcwxgUWd6AmGM6g/dv Zm9WPRK2CW0MiSrFOVSYJPfNaA== X-Received: by 2002:a6b:bc83:: with SMTP id m125mr6690201iof.83.1544379865420; Sun, 09 Dec 2018 10:24:25 -0800 (PST) Received: from cisco.lan (71-218-133-134.hlrn.qwest.net. [71.218.133.134]) by smtp.gmail.com with ESMTPSA id l25sm3270631ioj.68.2018.12.09.10.24.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Dec 2018 10:24:24 -0800 (PST) From: Tycho Andersen To: Kees Cook Cc: Andy Lutomirski , Oleg Nesterov , "Eric W . Biederman" , "Serge E . Hallyn" , Christian Brauner , Tyler Hicks , Akihiro Suda , Aleksa Sarai , Jann Horn , linux-kernel@vger.kernel.org, containers@lists.linux-foundation.org, linux-api@vger.kernel.org, Tycho Andersen Subject: [PATCH v10 1/4] seccomp: hoist struct seccomp_data recalculation higher Date: Sun, 9 Dec 2018 11:24:11 -0700 Message-Id: <20181209182414.30862-2-tycho@tycho.ws> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181209182414.30862-1-tycho@tycho.ws> References: <20181209182414.30862-1-tycho@tycho.ws> 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 In the next patch, we're going to use the sd pointer passed to __seccomp_filter() as the data to pass to userspace. Except that in some cases (__seccomp_filter(SECCOMP_RET_TRACE), emulate_vsyscall(), every time seccomp is inovked on power, etc.) the sd pointer will be NULL in order to force seccomp to recompute the register data. Previously this recomputation happened one level lower, in seccomp_run_filters(); this patch just moves it up a level higher to __seccomp_filter(). Thanks Oleg for spotting this. Signed-off-by: Tycho Andersen CC: Kees Cook CC: Andy Lutomirski CC: Oleg Nesterov CC: Eric W. Biederman CC: "Serge E. Hallyn" Acked-by: Serge Hallyn CC: Christian Brauner CC: Tyler Hicks CC: Akihiro Suda --- kernel/seccomp.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kernel/seccomp.c b/kernel/seccomp.c index f2ae2324c232..96afc32e041d 100644 --- a/kernel/seccomp.c +++ b/kernel/seccomp.c @@ -188,7 +188,6 @@ static int seccomp_check_filter(struct sock_filter *filter, unsigned int flen) static u32 seccomp_run_filters(const struct seccomp_data *sd, struct seccomp_filter **match) { - struct seccomp_data sd_local; u32 ret = SECCOMP_RET_ALLOW; /* Make sure cross-thread synced filter points somewhere sane. */ struct seccomp_filter *f = @@ -198,11 +197,6 @@ static u32 seccomp_run_filters(const struct seccomp_data *sd, if (WARN_ON(f == NULL)) return SECCOMP_RET_KILL_PROCESS; - if (!sd) { - populate_seccomp_data(&sd_local); - sd = &sd_local; - } - /* * All filters in the list are evaluated and the lowest BPF return * value always takes priority (ignoring the DATA). @@ -658,6 +652,7 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd, u32 filter_ret, action; struct seccomp_filter *match = NULL; int data; + struct seccomp_data sd_local; /* * Make sure that any changes to mode from another thread have @@ -665,6 +660,11 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd, */ rmb(); + if (!sd) { + populate_seccomp_data(&sd_local); + sd = &sd_local; + } + filter_ret = seccomp_run_filters(sd, &match); data = filter_ret & SECCOMP_RET_DATA; action = filter_ret & SECCOMP_RET_ACTION_FULL; -- 2.19.1