Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp653020ybs; Sun, 24 May 2020 17:08:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTDIz0+PxbkxAe0zTzSiTkcRil64QkMOmoyif46c0pLQLoLV0owJGoPJz2u3kF/1JSeLTc X-Received: by 2002:a17:906:4a8c:: with SMTP id x12mr16656609eju.279.1590365298292; Sun, 24 May 2020 17:08:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590365298; cv=none; d=google.com; s=arc-20160816; b=SqJMppXlNiE8s+lKc0j2m0iQnx8QqTYn6XHsjRgmygndICZ3uKTZEGASz86tDNOF3i M9VGLKJWVEjMFKq267fGwB49GJxY5/1XZ7Mfjzr1ra1Eq0D7S84Uq234tRFCAKuMN8Wz vr7F1JLsOWGVo+ue0We+nlwUKLmkZflXXo2AXFaFV0VTlEKVtyIkX4S7eFvnn5SKkl5V ffovhcCcEGIaxm2LtPnCJLDzDUvuCZyc2jaut9jAOFwKPmmTONiKxVNblSKpbCoL3CAO 5jHleW3dL14d9Sj8kVFDPPtL4thLsntUMql1yNzqu3USoKdSy1/EhCmGBpMB89/q2Wrr zzvg== 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=sGmbDpggpLO9WWe2AqQd1PedAXiRb0OI8EmgwIQ3Eck=; b=ETueUNl5FCrsQAwwKRKgJce5ZQeFRrlHxxT8sEum4c9SCCB+BDP0hZUJ/+AnFLhMoT d0zKEzmWCKW9RP9QMhmoOrSIvfg6Wwo2RyXQ0Z03DUp1ruwDS1WuI/g83yyj+wFLAMCN /o66jXkKF+6CcuR9ECkVfJR4W9+mQrdIvY4/Pdz8s4l3xzMuVGlbMibsoN3wLMqR7akv 4nJOov8Qy31gk12pZ4boOX3vL9Gr1xVn2p9uNZwW45DCXyP94G4oiFWKJY8aXY/qGUcZ jODYka1CsDc+77xKSNgAyAFdvj3JBRJZh4cttwkLTuf6v3gj/rHRWWalvdVdo4hfeM1h kj7g== 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 p6si8533841edh.66.2020.05.24.17.07.53; Sun, 24 May 2020 17:08:18 -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 S2388568AbgEYAFs (ORCPT + 99 others); Sun, 24 May 2020 20:05:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388149AbgEYAFs (ORCPT ); Sun, 24 May 2020 20:05:48 -0400 Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [IPv6:2002:c35c:fd02::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9876C061A0E; Sun, 24 May 2020 17:05:47 -0700 (PDT) Received: from viro by ZenIV.linux.org.uk with local (Exim 4.93 #3 (Red Hat Linux)) id 1jd0cb-00Euph-HX; Mon, 25 May 2020 00:05:37 +0000 Date: Mon, 25 May 2020 01:05:37 +0100 From: Al Viro To: Sargun Dhillon Cc: linux-kernel@vger.kernel.org, containers@lists.linux-foundation.org, linux-api@vger.kernel.org, christian.brauner@ubuntu.com, tycho@tycho.ws, keescook@chromium.org, cyphar@cyphar.com, Jeffrey Vander Stoep , jannh@google.com, rsesek@google.com, palmer@google.com, Matt Denton , Kees Cook Subject: Re: [PATCH 2/5] seccomp: Introduce addfd ioctl to seccomp user notifier Message-ID: <20200525000537.GB23230@ZenIV.linux.org.uk> References: <20200524233942.8702-1-sargun@sargun.me> <20200524233942.8702-3-sargun@sargun.me> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200524233942.8702-3-sargun@sargun.me> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, May 24, 2020 at 04:39:39PM -0700, Sargun Dhillon wrote: > +static void seccomp_handle_addfd(struct seccomp_kaddfd *addfd) > +{ > + int ret; > + > + /* > + * Remove the notification, and reset the list pointers, indicating > + * that it has been handled. > + */ > + list_del_init(&addfd->list); > + > + ret = security_file_receive(addfd->file); > + if (ret) > + goto out; > + > + if (addfd->fd >= 0) { > + ret = replace_fd(addfd->fd, addfd->file, addfd->flags); > + if (ret >= 0) > + fput(addfd->file); > + } else { > + ret = get_unused_fd_flags(addfd->flags); > + if (ret >= 0) > + fd_install(ret, addfd->file); Bad refcounting rules. *IF* we go with anything of that sort (and I'm not convinced that the entire series makes sense), it's better to have more uniform rules re reference consumption/disposal. Make the destructor of addfd *ALWAYS* drop its reference. And have this function go if (addfd->fd >= 0) { ret = replace_fd(addfd->fd, addfd->file, addfd->flags); } else { ret = get_unused_fd_flags(addfd->flags); if (ret >= 0) fd_install(ret, get_file(addfd->file)); }