Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8263386imu; Fri, 28 Dec 2018 14:03:00 -0800 (PST) X-Google-Smtp-Source: ALg8bN7PiDl0XOJRj1qkZBg1u2JmVKYfmotSgDuEUYP+6ZV24jXFQP/iNRcDMMqKoUFjmmLb0y7c X-Received: by 2002:a17:902:47aa:: with SMTP id r39mr28783718pld.219.1546034580282; Fri, 28 Dec 2018 14:03:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546034580; cv=none; d=google.com; s=arc-20160816; b=kIGnGW47j6URn8XeEd9qUAE8TEKJLeCUJHqFz1gXSsmNECTHjiXyKtiNN+HnFpW6NP Lua6okMhK89iJW5A7RgU89VQFHOlTM9XmexCjgjsp1xGqjqC7oQwbHh/xhTKM1s53Qub prj3yDQ/KS+iyhIPccZWH4hjc4GwjzNgyFAR+iUBVUKfxj/sJyn5Gtxzm1rK4hZueYje hBBcDRRxbstluquatsKr2BgjkATEOh9rDoEM+NTIQbgT8WjhmGbf/yvWyzoi0VDdISHs I0v2ScLAvf1a9QiwYP87rJCzlK3rXfjwNp8XFiajim+8Yj7VPst7cS9o9Yf6UU+spd4X 4uKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PCFdPZkOhVEeNJLbaMd6ZKs9erqnsy6xpaFd5c77MpY=; b=z4Hq0of5M2m+B98OKTvoLz/ZglAALFQyoUqgCUeHEkG0uWxMKAabuUbzZ5cMTSY6jy 7s9xrKzm5CokgStAqAVFddPxMr0LaBXNFHuju3eN4/JFQu79y94+/irX8+WubrrQ6k2P NGFTdHwVeib59yvCu12jWl++YxqTfLamvw7oGtek0yPxajZiOcV31kBeM+Zu63nNUPma nH+jPxyHHbi3sJc9m4skGsEXMo05oeOtp1MD0zNYWIMukTUEaY4SE4/5pNryKbLbbBmN /+fU2iLB49/sIt8wZOBQGcNZ2bylKvwN03mKISdAwQAYdeEjo4hoRfWYQsIbynvXquPW EUFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Sf+UMwpb; 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 h88si41942261pfa.49.2018.12.28.14.02.44; Fri, 28 Dec 2018 14:03:00 -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; dkim=pass header.i=@kernel.org header.s=default header.b=Sf+UMwpb; 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 S1732444AbeL1MP3 (ORCPT + 99 others); Fri, 28 Dec 2018 07:15:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:34492 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732244AbeL1MP0 (ORCPT ); Fri, 28 Dec 2018 07:15:26 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BB371218F0; Fri, 28 Dec 2018 12:15:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1545999326; bh=yI0MqnuWgBm4DRSxQ7CUx+PxBvmsb5JnRpnqpvXjh9Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sf+UMwpbeDew9iAA2Ug/cV6TIbjTPMOob67iVhS49BobTehIheS188Guy08myBSNJ qPa5xFlitXfUdJryvviaxm2ZfS4uY/IxDXYvP8NWFXPm6bkGdqXMFKPG87KS2Pwwgi 17qOHQs49TmMKkdDh9by6iZssYV4mPRPdydBuNsk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ivan Delalande , Al Viro Subject: [PATCH 4.19 45/46] proc/sysctl: dont return ENOMEM on lookup when a table is unregistering Date: Fri, 28 Dec 2018 12:52:39 +0100 Message-Id: <20181228113127.606449021@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20181228113124.971620049@linuxfoundation.org> References: <20181228113124.971620049@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ivan Delalande commit ea5751ccd665a2fd1b24f9af81f6167f0718c5f6 upstream. 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 deleted, which confuses our configuration daemon. The problem was successfully reproduced and this fix tested on v4.9.122 and v4.20-rc6. v2: return ERR_PTRs in all cases when proc_sys_make_inode fails instead of mixing them with NULL. Thanks Al Viro for the feedback. Fixes: ace0c791e6c3 ("proc/sysctl: Don't grab i_lock under sysctl_lock.") Cc: stable@vger.kernel.org Signed-off-by: Ivan Delalande Signed-off-by: Al Viro Signed-off-by: Greg Kroah-Hartman --- fs/proc/proc_sysctl.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -464,7 +464,7 @@ static struct inode *proc_sys_make_inode inode = new_inode(sb); if (!inode) - goto out; + return ERR_PTR(-ENOMEM); inode->i_ino = get_next_ino(); @@ -474,8 +474,7 @@ static struct inode *proc_sys_make_inode if (unlikely(head->unregistering)) { spin_unlock(&sysctl_lock); iput(inode); - inode = NULL; - goto out; + return ERR_PTR(-ENOENT); } ei->sysctl = head; ei->sysctl_entry = table; @@ -500,7 +499,6 @@ static struct inode *proc_sys_make_inode if (root->set_ownership) root->set_ownership(head, table, &inode->i_uid, &inode->i_gid); -out: return inode; } @@ -549,10 +547,11 @@ static struct dentry *proc_sys_lookup(st goto out; } - err = ERR_PTR(-ENOMEM); inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p); - if (!inode) + if (IS_ERR(inode)) { + err = ERR_CAST(inode); goto out; + } d_set_d_op(dentry, &proc_sys_dentry_operations); err = d_splice_alias(inode, dentry); @@ -685,7 +684,7 @@ static bool proc_sys_fill_cache(struct f if (d_in_lookup(child)) { struct dentry *res; inode = proc_sys_make_inode(dir->d_sb, head, table); - if (!inode) { + if (IS_ERR(inode)) { d_lookup_done(child); dput(child); return false;