Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp518690imu; Wed, 12 Dec 2018 22:59:40 -0800 (PST) X-Google-Smtp-Source: AFSGD/XYLjaSo87hU32Ogm8OlTZ42167ygjRNIs/o2Vo7G4jX15qACDpEA8o4GrxEfnHCRIrJIJe X-Received: by 2002:a63:1d1d:: with SMTP id d29mr21104648pgd.49.1544684379979; Wed, 12 Dec 2018 22:59:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544684379; cv=none; d=google.com; s=arc-20160816; b=NA76eZv2HB4wDCLCDEED+yGx3xbSXSY5DU0pPMIkJ4wt/rwYtPcj+qrtSuEg+msWQf QR88eGvqDkt1M0ZvFFnXnbCa0SDywAXWqUJKGgplqwQ66bNULlj+uJWpDTBk9Dq3+0XH IZY18vt0NwjFxBji50dEdA3yXYc43qdNFS2vpLDMLFT31FAZvrkJsqg7TVq7w0VOJ5RR OOIG8MwMcs28ns4VQrzl1YBS6pnfkGND3rm2u1ehkfDnIDfNsvfOZlxsPs0ox0pK9HV7 WdQBvlNCgsAjWkjy5/6nq9kz6YDfbNyF2dNRPJOKg4qsLiMCCBVm8CA9PfkztQ2fdLSP b22Q== 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=ST4nZc0hHJ3/M8hcSbqvWmMOlJXc/zW0S9ejy2IoIPs=; b=T19DLLTLNarVb6VelByW4hCIkdS9dVHE4YDFC+uGAu7tsTR2IAgF+vYn1d0a43RpKf pCCaSmvOgKHRel5MvX15sOalpKiRzALeP/HD6OzAKCuK2UuPOuOoJEvRHMEwVrKh9lt1 7igKHwtddtkJJCM+W2vbfkXW3rj1J7THPECu7rP0cm5vwfCp754QsC+H0W5N6D1aiUHe Ye2g70Cx//yND410Tco78qKMChSbwy9xQl8Js2C/fzzuOPGCxROPps6SongXsEhihmU3 I0NcHlzGESq4z2WZiCK0P0bwiYsrbwLOboOkcetNULedT8HAqVWMKyPkO7F0B6y63Hph GxaQ== 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 p64si934617pfa.94.2018.12.12.22.59.25; Wed, 12 Dec 2018 22:59:39 -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 S1726930AbeLMG6h (ORCPT + 99 others); Thu, 13 Dec 2018 01:58:37 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:40516 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726542AbeLMG6h (ORCPT ); Thu, 13 Dec 2018 01:58:37 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.91 #2 (Red Hat Linux)) id 1gXKx0-0006KL-8m; Thu, 13 Dec 2018 06:58:26 +0000 Date: Thu, 13 Dec 2018 06:58:26 +0000 From: Al Viro To: Ivan Delalande Cc: Luis Chamberlain , Kees Cook , Andrew Morton , "Eric W. Biederman" , Alexey Dobriyan , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH] proc/sysctl: don't return ENOMEM on lookup when a table is unregistering Message-ID: <20181213065826.GL2217@ZenIV.linux.org.uk> References: <20181213015742.GA28776@visor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181213015742.GA28776@visor> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 12, 2018 at 05:57:43PM -0800, Ivan Delalande wrote: > proc_sys_lookup can fail with ENOMEM instead of ENOENT when the > corresponding sysctl table is being unregistered. In our case we see > this upon opening /proc/sys/net/*/conf files while network interfaces > are being removed, which confuses our configuration daemon. > > The problem was successfully reproduced and this fix tested on v4.9.122 > and v4.20-rc6. > > Fixes: ace0c791e6c3 ("proc/sysctl: Don't grab i_lock under sysctl_lock.") > Cc: stable@vger.kernel.org > Signed-off-by: Ivan Delalande > --- > fs/proc/proc_sysctl.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c > index 89921a0d2ebb..834be5bc3d07 100644 > --- a/fs/proc/proc_sysctl.c > +++ b/fs/proc/proc_sysctl.c > @@ -474,7 +474,7 @@ static struct inode *proc_sys_make_inode(struct super_block *sb, > if (unlikely(head->unregistering)) { > spin_unlock(&sysctl_lock); > iput(inode); > - inode = NULL; > + inode = ERR_PTR(-ENOENT); > goto out; > } > ei->sysctl = head; > @@ -549,10 +549,11 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry, > goto out; > } > > - err = ERR_PTR(-ENOMEM); > inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p); > - if (!inode) > + if (IS_ERR_OR_NULL(inode)) { > + err = inode ? ERR_CAST(inode) : ERR_PTR(-ENOMEM); *gags* If you want to return specific errors, do just that and for pity sake, do *NOT* invent such hybrids. "Pointer to object on success, ERR_PTR(-E...) on failure, NULL means ERR_PTR(-ENOMEM)" is a bitch to reason about and prone to breakage. "Return NULL on error" and "return ERR_PTR() on error" do not mix. Just make proc_sys_make_inode() return ERR_PTR(-ENOMEM) on allocation failures and update the callers (as you have to, anyway). IS_ERR_OR_NULL() is usually a sign of bad calling conventions and it certainly is just that in this case. Just do inode = new_inode(sb); if (!inode) return ERR_PTR(-ENOMEM); in there, in addition to your return of ERR_PTR(-ENOENT), and lose those IS_ERR_OR_NULL() things. Make those IS_ERR() and turn the assignment to err into straight ERR_CAST(). All there is to it...