Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6528882imu; Sun, 2 Dec 2018 20:55:04 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xv2I++1+tAKgbpls62gSdWKTI8rfty5EJgxncpr94vNydmQtOxhoXWfkbm2tqZxh54s9a/ X-Received: by 2002:a62:4e49:: with SMTP id c70mr14334187pfb.167.1543812904642; Sun, 02 Dec 2018 20:55:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543812904; cv=none; d=google.com; s=arc-20160816; b=UkkqfXgo1ujTyPXL5vBj5dh9Ae5MqrnWHi1PMUa1d5ZnSBx3PssR5HJB0pc+qIyjCt TNRoBMtxO97ANE4opOTB3t9/M93B59MOPmCuJiY/qp3GdgMx/tzC/DAkPselZSZNQ06C c1l4uhmwse0WyG+fKLC+Vels9GUNeyq4UIIewU0V29tlTW2I9ihJYpEQAU82hqvPSOHm P3CyuLOumqNNacwfdJXFEVgB8uSA2qH7vMpjCdUdqoMsVgsSxjn9c/vDbQjvxhDKxxSc PCjM6Hw0qus1WqSyxUeB85BAYbPoszlxAkEd8aZfHsocrbIN9SXSqLPNO4uD/NusnJDY LBxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=ddnSQac6iDxB23vkEXalk2ShmOMwMZpwk26vgA9p/jQ=; b=zn0lv6+USlmUwJt+gdS8DS+2hdlS9lR1pPH7748LYEDHQ1cxWYzPXCO4clygmnPxfg SSCNHIrcsiv1RZfQd7QqF1L7hvjc1i16vVxOMlRwKjc8QFLIrQP9IO+F0cs8A8vhFfsw sEBHHlO1TWpOBaCCUOo3shKqG2ApGPeZcdDuBJzH2bPq8nOV5ZNgQp83Fo1Te/3nzEgg n6bVnU2tgZbokQF8zDhmeMphhZNZBHkEgBU79ZopDX2lMV8sCeTPxgHJIgDh0ZdXNBBS Ce5tg7R8fT0So4WLgJ8tEXXgMNIHDBZbtcdyuxpT1rx8EnPi3iNz1m8+mWNrBvPy9CxE CLNQ== ARC-Authentication-Results: i=1; mx.google.com; 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 x3si11442724pgj.493.2018.12.02.20.54.49; Sun, 02 Dec 2018 20:55:04 -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; 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 S1725872AbeLCExc (ORCPT + 99 others); Sun, 2 Dec 2018 23:53:32 -0500 Received: from mail.hallyn.com ([178.63.66.53]:54380 "EHLO mail.hallyn.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725790AbeLCExc (ORCPT ); Sun, 2 Dec 2018 23:53:32 -0500 Received: by mail.hallyn.com (Postfix, from userid 1001) id 9DC12F46; Sun, 2 Dec 2018 22:53:29 -0600 (CST) Date: Sun, 2 Dec 2018 22:53:29 -0600 From: "Serge E. Hallyn" To: Tycho Andersen Cc: Kees Cook , 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 Subject: Re: [PATCH v9 1/4] seccomp: hoist struct seccomp_data recalculation higher Message-ID: <20181203045329.GA31406@mail.hallyn.com> References: <20181203032827.27978-1-tycho@tycho.ws> <20181203032827.27978-2-tycho@tycho.ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181203032827.27978-2-tycho@tycho.ws> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Dec 02, 2018 at 08:28:24PM -0700, Tycho Andersen wrote: > 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