Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3905238pxy; Mon, 26 Apr 2021 12:38:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsZTahG3VPKSqrc1FVNCp408Hu6l3I6O4twlL1QDuBS3H/WPct1YURCUNgNkUHioofEPw6 X-Received: by 2002:a17:907:2d0f:: with SMTP id gs15mr3637248ejc.113.1619465887229; Mon, 26 Apr 2021 12:38:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619465887; cv=none; d=google.com; s=arc-20160816; b=savTZF5JUpL3fOb8Z3oNvSboYUi2J/5xdGCxlZOnm1680StF28zNJVqqDxpjEyWR5a 3cCmkdnqSIs3Snqs5CHQrSgxhFqVACCN162mYeUh8sXN1ThzT/CDwB4CWYniHnSnSnDP f6rKUkbM03oV/FKDoRihjYyX0Zrk+wxCBW9V4pZ7NfB+pDg2V9C9dyVIQ+s7kG3PyAZU q3Xm6vUWlQ0IphbrZiw4afgmtkHfwl0X88Xi1gWMRAItHYu3nB8HT0Od7hULypStwukQ 1HWyVnDAzkaGmZVmJTUANkghZGgDkw8PbgJ4gd5M41AJxK4MZOiIYxuvlO/KO0XFOfnB pjPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=jlblDGKKV68vfiveJhVJ8dGvoNhvhfHu+cqRN1LYftE=; b=GOwj/U+zEZZlvYNHyXL8sVzB1DE5MIx65h4lqsCjzwFmRkGWm7fig+DcuMDDl2PAXk qHdOIVQaOT/h2CvfL6uT/RpG/muiqTwPtCALh+uqDMvu74yEe2X0msSmH8BE77pBgLwn pdeA/kEpJ4KuQJtpFK4uSiSN42PUaLATzQ7sqTj5IWqLdEhSCFrhjRohGbKFVFV3CpOU 9uFOwA/BDvKpg1DshfL69Yu41mGA7S3gLscHH0HYzfjMQWSqrqQmL1V6b2h1/btbftpm T3ELH4LL5ErQ1kpb7gIVytVdjhU0ckz9Q0OtTm+4BiViqcFXo5YW4qBvLxHpajcun13V 4quQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tycho.pizza header.s=fm3 header.b=6uRE5o4e; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=Oi6UozXj; 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 w1si582502edv.136.2021.04.26.12.37.43; Mon, 26 Apr 2021 12:38:07 -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; dkim=pass header.i=@tycho.pizza header.s=fm3 header.b=6uRE5o4e; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=Oi6UozXj; 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 S239997AbhDZTD5 (ORCPT + 99 others); Mon, 26 Apr 2021 15:03:57 -0400 Received: from new4-smtp.messagingengine.com ([66.111.4.230]:34497 "EHLO new4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239897AbhDZTD3 (ORCPT ); Mon, 26 Apr 2021 15:03:29 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailnew.nyi.internal (Postfix) with ESMTP id 6DD395803EE; Mon, 26 Apr 2021 15:02:32 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 26 Apr 2021 15:02:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tycho.pizza; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=jlblDGKKV68vfiveJhVJ8dGvoNh vhfHu+cqRN1LYftE=; b=6uRE5o4evdjcVrMLLg4VChLZMlox1EIpQvg512h2ttT 0cqWGEvLxtWSle4WMHIY8HfsaN2BNM2yhGvTIukOVieT1x/yuHWJ0HIblahhREX1 lkYcwJX96BeASy2Y2Nvq7HdFQfPOflXr9aTGjE2O5unI12sFk3rnmhdYedZyC6Fy f3gjfvvyh9cLGtq/oXnopjVQFWeZwY3fHE52WNglSTMrNS+AhvgGk8oHw62h2xO2 w84apisB9ajInCMevTFAp+8Y8F6nb2aV0V860VVhlG0QRDBsXyzPyghKOjP50Mjc SOo9tbzDoO638yXZdTH4f58foIME3MXh+UvkbNLD5TA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=jlblDG KKV68vfiveJhVJ8dGvoNhvhfHu+cqRN1LYftE=; b=Oi6UozXjCLyKLEBgVVwTln Q1JMo0Whhdo4r2iofXS5dE1si64zw18X60KHi8vWK5PQDfOteziedsVPUn/A7xXd +SRHYy2sAS9FoiMEhSqGjPj26MBsAAi8urRc+nkMSvm1Z5e1Oe2kTZ8bbZ6er4bw OYSSvbXPqr49fTqPxTuVCQ+D3ZgeBnTenFZwm4zwY+fbcTbiZi3TNlTmbC2V8U/Y pGjMzNTHLqCf8moceRABm5m804MqElA8jqIKjaON+AvD9d2O1jHptaozyaQaSYdX a6aPxNPC0O7y11uNT+u513SMvKv7TbAO630ry6WiF6+avnH6ZRlUkbnuOjpEF7Kw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvddukedgudefgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepvfihtghh ohcutehnuggvrhhsvghnuceothihtghhohesthihtghhohdrphhiiiiirgeqnecuggftrf grthhtvghrnhepgeekfeejgeektdejgfefudelkeeuteejgefhhfeugffffeelheegieef vdfgtefhnecukfhppedujeefrdefkedruddujedrkeehnecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomhepthihtghhohesthihtghhohdrphhiiiii rg X-ME-Proxy: Received: from cisco (unknown [173.38.117.85]) by mail.messagingengine.com (Postfix) with ESMTPA id D31661080066; Mon, 26 Apr 2021 15:02:30 -0400 (EDT) Date: Mon, 26 Apr 2021 13:02:29 -0600 From: Tycho Andersen To: Sargun Dhillon Cc: Kees Cook , LKML , Linux Containers , Rodrigo Campos , Christian Brauner , Mauricio =?iso-8859-1?Q?V=E1squez?= Bernal , Giuseppe Scrivano , Andy Lutomirski , Will Drewry , Alban Crequy Subject: Re: [PATCH RESEND 2/5] seccomp: Add wait_killable semantic to seccomp user notifier Message-ID: <20210426190229.GB1605795@cisco> References: <20210426180610.2363-1-sargun@sargun.me> <20210426180610.2363-3-sargun@sargun.me> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210426180610.2363-3-sargun@sargun.me> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 26, 2021 at 11:06:07AM -0700, Sargun Dhillon wrote: > @@ -1103,11 +1111,31 @@ static int seccomp_do_user_notification(int this_syscall, > * This is where we wait for a reply from userspace. > */ > do { > + interruptible = notification_interruptible(&n); > + > mutex_unlock(&match->notify_lock); > - err = wait_for_completion_interruptible(&n.ready); > + if (interruptible) > + err = wait_for_completion_interruptible(&n.ready); > + else > + err = wait_for_completion_killable(&n.ready); > mutex_lock(&match->notify_lock); > - if (err != 0) > + > + if (err != 0) { > + /* > + * There is a race condition here where if the > + * notification was received with the > + * SECCOMP_USER_NOTIF_FLAG_WAIT_KILLABLE flag, but a > + * non-fatal signal was received before we could > + * transition we could erroneously end our wait early. > + * > + * The next wait for completion will ensure the signal > + * was not fatal. > + */ > + if (interruptible && !notification_interruptible(&n)) > + continue; I'm trying to understand how one would hit this race, > @@ -1457,6 +1487,12 @@ static long seccomp_notify_recv(struct seccomp_filter *filter, > unotif.pid = task_pid_vnr(knotif->task); > unotif.data = *(knotif->data); > > + if (unotif.flags & SECCOMP_USER_NOTIF_FLAG_WAIT_KILLABLE) { > + knotif->wait_killable = true; > + complete(&knotif->ready); > + } > + > + > knotif->state = SECCOMP_NOTIFY_SENT; > wake_up_poll(&filter->wqh, EPOLLOUT | EPOLLWRNORM); > ret = 0; Seems like the idea is that if someone does a ioctl(RECV, ...) twice they'll hit it? But doesn't the test for NOTIFY_INIT and return -ENOENT above this hunk prevent that? Thanks, Tycho