Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp398415ybm; Fri, 29 May 2020 03:00:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzs1lGkrw5WzAQjSzN9cutZ/xO+esAjYwOGOyGtImIbRKn+Os7Wal8Oqomg5Bl45rQS/y6K X-Received: by 2002:a17:906:4a03:: with SMTP id w3mr6824306eju.154.1590746443358; Fri, 29 May 2020 03:00:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590746443; cv=none; d=google.com; s=arc-20160816; b=QZaAyO8O8Ve07I/uN66EQqtSR+uXbHkQgdUzV78YQvUXnc9MINba7+w+djj6S9IU01 Qqh+xyycm/64a9PXhSTaDhw+0EQ2CgGEv0QmQdgKGx7BH6WPlmDFkwBv3sOu0CGT8Wl9 J8IDgT3Aa0rG/XNr50ZMcspdZXpw/cf5UU+r9iYKkFka5luPMcgjS/PhNbWu684dbXsw XOUbDtS1lM6i9zBuCxAV6e2mK7Ts7NtnWT5hOTTuXw8X0nNZDka9XGpMvqxvF9IElrU8 WR+Jej4iUiEd9b3pO0uSGelLdApWgRoAnE3kMXKgA+eodufQaXdnz8sTaido/uxP/hIJ V0xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=txo4vjTM27MeZJzRE2+AjH67N+eM+2UlDqX6+xCb9IU=; b=u25MGO6zYX4bQ/ulRY59TaO6mdV4d/dZJgvllLvS8kWyvhkOyEI6He4n6H5fER5YND GbdvgGkI8KtgVoaoB3F+y5fuV4Bv3K4KISNbnNXRC7j0sZxlB0L7Lpu+q5K0wEpCZqSj QOsMSDWzykZSIYeYV850PbxV+4G8HPw4zobevRPZv5AIttBv1RMDEtFmUzQVjOaujWgC 3GCNoCJeyqJFhdf32Qn/2rozoNK18c12PQM6u71XY2fkrYNKmAocMMYSbse7aS16UUco hj4cPX7AGzkr79TkM52IiLPSYEgVsMV54l4bj3V5Md/0Cgh4N0kn7ukm4aPWEYxoUV66 vBEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g7si5010966ejx.451.2020.05.29.03.00.19; Fri, 29 May 2020 03:00:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726495AbgE2J6I (ORCPT + 99 others); Fri, 29 May 2020 05:58:08 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:38449 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725601AbgE2J6E (ORCPT ); Fri, 29 May 2020 05:58:04 -0400 Received: from ip5f5af183.dynamic.kabel-deutschland.de ([95.90.241.131] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jebm0-00055Y-M2; Fri, 29 May 2020 09:57:56 +0000 Date: Fri, 29 May 2020 11:57:55 +0200 From: Christian Brauner To: Sargun Dhillon Cc: keescook@chromium.org, containers@lists.linux-foundation.org, cyphar@cyphar.com, jannh@google.com, jeffv@google.com, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, palmer@google.com, rsesek@google.com, tycho@tycho.ws, Matt Denton , Kees Cook Subject: Re: [PATCH v2 1/3] seccomp: Add find_notification helper Message-ID: <20200529095755.jv77m4qwtzr63do6@wittgenstein> References: <20200528110858.3265-1-sargun@sargun.me> <20200528110858.3265-2-sargun@sargun.me> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200528110858.3265-2-sargun@sargun.me> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 28, 2020 at 04:08:56AM -0700, Sargun Dhillon wrote: > This adds a helper which can iterate through a seccomp_filter to > find a notification matching an ID. It removes several replicated > chunks of code. > > Signed-off-by: Sargun Dhillon > Cc: Matt Denton > Cc: Kees Cook , > Cc: Jann Horn , > Cc: Robert Sesek , > Cc: Chris Palmer > Cc: Christian Brauner > Cc: Tycho Andersen > --- A single nit below otherwise: Acked-by: Christian Brauner > kernel/seccomp.c | 51 ++++++++++++++++++++++++------------------------ > 1 file changed, 25 insertions(+), 26 deletions(-) > > diff --git a/kernel/seccomp.c b/kernel/seccomp.c > index 55a6184f5990..94ae4c7502cc 100644 > --- a/kernel/seccomp.c > +++ b/kernel/seccomp.c > @@ -1021,10 +1021,25 @@ static int seccomp_notify_release(struct inode *inode, struct file *file) > return 0; > } > > +/* must be called with notif_lock held */ > +static inline struct seccomp_knotif * > +find_notification(struct seccomp_filter *filter, u64 id) > +{ > + struct seccomp_knotif *cur; > + > + list_for_each_entry(cur, &filter->notif->notifications, list) { > + if (cur->id == id) > + return cur; > + } > + > + return NULL; > +} > + > + > static long seccomp_notify_recv(struct seccomp_filter *filter, > void __user *buf) > { > - struct seccomp_knotif *knotif = NULL, *cur; > + struct seccomp_knotif *knotif, *cur; > struct seccomp_notif unotif; > ssize_t ret; > > @@ -1078,14 +1093,8 @@ static long seccomp_notify_recv(struct seccomp_filter *filter, > * may have died when we released the lock, so we need to make > * sure it's still around. > */ > - knotif = NULL; > mutex_lock(&filter->notify_lock); > - list_for_each_entry(cur, &filter->notif->notifications, list) { > - if (cur->id == unotif.id) { > - knotif = cur; > - break; > - } > - } > + knotif = find_notification(filter, unotif.id); > > if (knotif) { Nit: additional \n which isn't present before any of the other new find_notification() invocations.