Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3596862pxv; Mon, 28 Jun 2021 08:13:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxd0YPUmsIRip1XkFIoLDdi0dsCKqrrS6AYfSuclHEY8Uan6/Et11cY6bDurzuyDVEveton X-Received: by 2002:a05:6602:58e:: with SMTP id v14mr14134011iox.181.1624893239062; Mon, 28 Jun 2021 08:13:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624893239; cv=none; d=google.com; s=arc-20160816; b=aO6aPJe7MG/fI4C/mUz3vafn0UaTYS8+DfWGUZAzu9vBOS0yvhyd3HLufct3Y/ejsD 6YMkmqVFbtMp+3n7sIKrpYTCSiwkB6S/aP0nLcg1exxuWewKS9JH9oTAxR1dpIHxTtVW m/flgSdxv6IpDQDf/jvPG+WYrvy3wrNh/YPlCfa3Iwf+CE8Fkfk11wyDFb6VFNNiMM4S ix4tf93iTToTU/SPODIxwIVLRsGbQ6dZ1W5r0qUW8MKyLJ4/fqHhWKFMIYNHmMlX5khs D88fmkXEpSllj2yQeUoJJIb5r+6f3JvVj+UJV3cHPd7pcLQoYkxlQuAcb1xTDlCXzm5H FgAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MUbpr/g+UgSFxsTY5jacRZfa+cqfylM5GmOY9rwhM54=; b=RFaSU3rrJaJIFGq0i8lhJPDhVUOTNG++07UzrfhtIyYboCGE+rdeQ3Unz0xb8PzfBk UXNnFxI4PqmE76WDVmp1aFGzJaHr/0VWNFVqv0fbgZBe7s3adQDiSlQC9omiKsVDKJeS rG9KPpGEWJRxNE1jBkV1u0We6w3ZRFbtkuESIxh2ZzHI1lRu/6+MCANACvhZ0dLreaaj I0YFpUjwkCff3pz4MXLUIT2dQqmW+/mzw+e0250Mcy2CKOtl4TWsR4lPmEXmi8W1dPLO nOt1ZhT4EdWRO6PocPMV637gDeMSqSjRmKBivoew6bXzwjCnUwpSMVsPQk6shhDGZl2w o7Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Mvh9qlMm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l8si17807798ilk.17.2021.06.28.08.13.42; Mon, 28 Jun 2021 08:13:59 -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=@kernel.org header.s=k20201202 header.b=Mvh9qlMm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237799AbhF1POk (ORCPT + 99 others); Mon, 28 Jun 2021 11:14:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:59764 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235865AbhF1OxD (ORCPT ); Mon, 28 Jun 2021 10:53:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 32A4B61D37; Mon, 28 Jun 2021 14:37:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624891044; bh=HxIbMjLZ3pfTFH/OuSuLE3sjYWU92k1375vx+sIZZ6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mvh9qlMmKuelqzX/rjcUJ/KJVHCTsfrPLKVRfGv4nqMv0DrUodYwBo9jSlrQP9dLm w30U7u/2xOVc/mtGbXMteeht3l+22NOUO1Sf3jlQbKSPGqlrEb0dfbvY6+s6qUmhn6 cizRq/EJ0/+MCNji4xQWy5NbscLdt7768FjNBFmIyQ395ap74B9sROZaVRs5gWpXh8 CmPySHDYq8im0Jcx4E63+evKhS4aL2lJnz+utk4/BIjN+ZHcIa/BUpwAT6f50MR9HK CHx/93TqU56HQKZAOYWdEGzK3sOd0f5bRNUqMmXxOhOylkWEfJxxcoXL4n5p50HHPy Cjc/GawMLyUGw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Al Viro , "Guilherme G . Piccoli" , Greg Kroah-Hartman Subject: [PATCH 4.14 63/88] unfuck sysfs_mount() Date: Mon, 28 Jun 2021 10:36:03 -0400 Message-Id: <20210628143628.33342-64-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628143628.33342-1-sashal@kernel.org> References: <20210628143628.33342-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.14.238-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.14.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.14.238-rc1 X-KernelTest-Deadline: 2021-06-30T14:36+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro commit 7b745a4e4051e1bbce40e0b1c2cf636c70583aa4 upstream. new_sb is left uninitialized in case of early failures in kernfs_mount_ns(), and while IS_ERR(root) is true in all such cases, using IS_ERR(root) || !new_sb is not a solution - IS_ERR(root) is true in some cases when new_sb is true. Make sure new_sb is initialized (and matches the reality) in all cases and fix the condition for dropping kobj reference - we want it done precisely in those situations where the reference has not been transferred into a new super_block instance. Signed-off-by: Al Viro Signed-off-by: Guilherme G. Piccoli Signed-off-by: Greg Kroah-Hartman --- fs/sysfs/mount.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c index 20b8f82e115b..2bbe84d9c0a8 100644 --- a/fs/sysfs/mount.c +++ b/fs/sysfs/mount.c @@ -28,7 +28,7 @@ static struct dentry *sysfs_mount(struct file_system_type *fs_type, { struct dentry *root; void *ns; - bool new_sb; + bool new_sb = false; if (!(flags & MS_KERNMOUNT)) { if (!kobj_ns_current_may_mount(KOBJ_NS_TYPE_NET)) @@ -38,9 +38,9 @@ static struct dentry *sysfs_mount(struct file_system_type *fs_type, ns = kobj_ns_grab_current(KOBJ_NS_TYPE_NET); root = kernfs_mount_ns(fs_type, flags, sysfs_root, SYSFS_MAGIC, &new_sb, ns); - if (IS_ERR(root) || !new_sb) + if (!new_sb) kobj_ns_drop(KOBJ_NS_TYPE_NET, ns); - else if (new_sb) + else if (!IS_ERR(root)) root->d_sb->s_iflags |= SB_I_USERNS_VISIBLE; return root; -- 2.30.2