From patchwork Wed Jun 30 19:00:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guilherme G. Piccoli" X-Patchwork-Id: 1499083 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GFVz76kzwz9sWD; Thu, 1 Jul 2021 05:00:19 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1lyfRY-0002eJ-CL; Wed, 30 Jun 2021 19:00:16 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lyfRW-0002dl-O3 for kernel-team@lists.ubuntu.com; Wed, 30 Jun 2021 19:00:14 +0000 Received: from mail-pf1-f199.google.com ([209.85.210.199]) by youngberry.canonical.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lyfRW-0004SW-GW for kernel-team@lists.ubuntu.com; Wed, 30 Jun 2021 19:00:14 +0000 Received: by mail-pf1-f199.google.com with SMTP id s15-20020a056a0008cfb0290306b50a28ecso2349237pfu.10 for ; Wed, 30 Jun 2021 12:00:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GkH1Qv0KhB7tlzCnYUn8JtfFFGivLuvaUgSgW9cQKY8=; b=cxkzzPrI32jjgsp+JYMY6e4nWCGXWj+fS5bmD5t0mMDbWmWkLYZaa9KbuUjpBuK6VU wN6vHYneCLVrEzAv6SW//C2ZGiyd+ZjWO0w5/f1X9SqRJAeeigvO8SuCeYiDpW9gfDk+ jkWwYlj8Hyq1GEXxtE/8gaHeniRPmqMgCM2I79XHSbcz3GgYKKas3taqI4L9REynrBTE kjbT5dpKZeH9PWo2/5Or6HSaaOcNXUFj+3uHZ6gpORwy0A40wHxReYjhOmQeUeX+w5cx sWhfXYrDdw9A/Mcp8AT5u00ZJrtYIVqerKSyxseFS0+KLDPUfRCyhirg8SzztNvz7drH qoOQ== X-Gm-Message-State: AOAM53127j9PhrxDWkOI00ajeXqbeOPOjKPd6vBeX/iNbXtfDocI0I1Z QKDTCq4w1l9xvY/DbZhnMXbK8xYPJTKB5ZHr3w/OzWPC+NFqHpwVm1INgH3EwusWLO/+b9A4Rtc C+TvFu7cXfSWg0PapqFw1VPPyEdqGBwETKhUP0BkxAA== X-Received: by 2002:a17:90b:3712:: with SMTP id mg18mr22982065pjb.164.1625079613131; Wed, 30 Jun 2021 12:00:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfWzyiDz4VQZx+u83GckIFAXVs/LhrGl8yHi1UllPWou8LzVFCTiRui1FWMdnq1b8LAJSunw== X-Received: by 2002:a17:90b:3712:: with SMTP id mg18mr22982055pjb.164.1625079612944; Wed, 30 Jun 2021 12:00:12 -0700 (PDT) Received: from localhost ([187.183.41.59]) by smtp.gmail.com with ESMTPSA id v6sm24577810pgk.33.2021.06.30.12.00.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Jun 2021 12:00:12 -0700 (PDT) From: "Guilherme G. Piccoli" To: kernel-team@lists.ubuntu.com Subject: [B][PATCH 2/2] unfuck sysfs_mount() Date: Wed, 30 Jun 2021 16:00:01 -0300 Message-Id: <20210630190001.6112-3-gpiccoli@canonical.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210630190001.6112-1-gpiccoli@canonical.com> References: <20210630190001.6112-1-gpiccoli@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pedro.principeza@canonical.com Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Al Viro BugLink: https://bugs.launchpad.net/bugs/1934175 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 (cherry picked from commit 7b745a4e4051e1bbce40e0b1c2cf636c70583aa4) Signed-off-by: Guilherme G. Piccoli Acked-by: Thadeu Lima de Souza Cascardo --- 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 fb49510c5dcf..88b388415d0e 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 & SB_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;