Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp873092imd; Thu, 1 Nov 2018 06:57:29 -0700 (PDT) X-Google-Smtp-Source: AJdET5cX2GMjB18V27O6gfHOMYQ6P2H+RCYtAL50pKJxqF42yxpzsUuVS2ZicuWitmbSHdQufygv X-Received: by 2002:a63:2586:: with SMTP id l128mr7434059pgl.104.1541080649100; Thu, 01 Nov 2018 06:57:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541080649; cv=none; d=google.com; s=arc-20160816; b=hWaeY8CQQKDbzz4ejlxOpmdRQrlXdFIs+aj4n5ohEz2Z7MoF7a8XPeXEjbguj2gE0T Dw5AAwZOiYL1GBUgWP1PaP58MtmWqI1dPDsGeW7eFpa7eexVRU+GU+8NhvK2FCpGruAP bFskAt69rVVOTn964Y7wCzeCYJaXDTj1GusxkeWGyOOyGe6qHYAOMF7ZOSc81AEj/Ywn kH2oYknnJ8kyCF+bQ2KiHqbvnBqS613MrC0xwg+DqA73NOv9dzxg0SI7up7CbMEssOF1 CFmzmf0TrpDHlv7+mnTovieA29ANv0gcBKqVkSmmWYUAKFwdTMnsZSOA96HJecnTzfxf pz9Q== 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=6GZgWikZZ2g5HCj8rkfNgc1zrydUznjk7kC6OvraTiI=; b=pDlzWiIO07hwqD0vZUqhsZBmpADIe8ZTtkHT/K3t2WxY53d9kUnM5KIY214rLfAHWP UoCM1GjQTNy7jcUPmc5sPiQJRbUMUTXEfKSVNvBh50fAd8mA7d0/rGSupHykxAjL/oMe 85tNXdhVkcAc3ZECDF7naODYP4eCckt6yV1k6L+JaPYNMaB0Ds5cvJrENPNJ5IwVpUHJ sG6xoIZOZA5Y+TUSZugRDgbQ10DwR4AmriXXrL/2REoO10kBENROoJ1320ioxJFpSRMM xMJxFcPgANBtGUO9Ugvgboh0FBynOrLEx7dPKKhRKH9NUi5Og/9Bydkq7ajSLbNhRL1Z FiEQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bb3-v6si3123395plb.421.2018.11.01.06.57.14; Thu, 01 Nov 2018 06:57:29 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728768AbeKAW7n (ORCPT + 99 others); Thu, 1 Nov 2018 18:59:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55493 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728500AbeKAW7n (ORCPT ); Thu, 1 Nov 2018 18:59:43 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 043B27F3FF; Thu, 1 Nov 2018 13:56:39 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.43.17.31]) by smtp.corp.redhat.com (Postfix) with SMTP id 64D365D6B5; Thu, 1 Nov 2018 13:56:36 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 1 Nov 2018 14:56:37 +0100 (CET) Date: Thu, 1 Nov 2018 14:56:34 +0100 From: Oleg Nesterov To: Tycho Andersen Cc: Kees Cook , Andy Lutomirski , "Eric W . Biederman" , "Serge E . Hallyn" , Christian Brauner , Tyler Hicks , Akihiro Suda , Aleksa Sarai , linux-kernel@vger.kernel.org, containers@lists.linux-foundation.org, linux-api@vger.kernel.org Subject: Re: [PATCH v8 1/2] seccomp: add a return code to trap to userspace Message-ID: <20181101135633.GB23232@redhat.com> References: <20181029224031.29809-1-tycho@tycho.ws> <20181029224031.29809-2-tycho@tycho.ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181029224031.29809-2-tycho@tycho.ws> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 01 Nov 2018 13:56:39 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/29, Tycho Andersen wrote: > > +static int seccomp_notify_release(struct inode *inode, struct file *file) > +{ > + struct seccomp_filter *filter = file->private_data; > + struct seccomp_knotif *knotif; > + > + mutex_lock(&filter->notify_lock); > + > + /* > + * If this file is being closed because e.g. the task who owned it > + * died, let's wake everyone up who was waiting on us. > + */ > + list_for_each_entry(knotif, &filter->notif->notifications, list) { > + if (knotif->state == SECCOMP_NOTIFY_REPLIED) > + continue; > + > + knotif->state = SECCOMP_NOTIFY_REPLIED; > + knotif->error = -ENOSYS; > + knotif->val = 0; > + > + complete(&knotif->ready); > + } > + > + wake_up_all(&filter->notif->wqh); Why? __fput() is not possible if there is another user of this file sleeping in seccomp_notify_poll(). > + kfree(filter->notif); Hmm, this looks wrong... we can't kfree ->notif if its ->notifications list is not empty, otherwise seccomp_do_user_notification()->list_del(&n.list) can write to the freed memory. I think _release() should do list_for_each_entry_safe() + list_del_init() and seccomp_do_user_notification() should use list_del_init() too. Or, simpler, seccomp_do_user_notification() should do if (!match->notif) goto out; instead of "goto remove_list". Oleg.