Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1289123pxm; Thu, 3 Mar 2022 14:21:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJzutL3Rh+FGpYX8ft6aeQ01O7tnrj53VfnVmgSgZWQxcz5g9lMlvccekCZ+wN5PfWL3AVnJ X-Received: by 2002:a62:6492:0:b0:4f6:3c39:c0bc with SMTP id y140-20020a626492000000b004f63c39c0bcmr13451052pfb.74.1646346080301; Thu, 03 Mar 2022 14:21:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646346080; cv=none; d=google.com; s=arc-20160816; b=ajnjP1lYpd7W+oLIMSSwWIB4to3g153qxSgFaKd3nYurdcPIRavMcKOuAWSmRqNSzL mGPqEnLYWG0n6W2V0SGCP/9DAIeo2YEycEHwm6+192zziiNr4mpAQM5ZCsplgqIJ/HCB ysljpX2E3Jt8BTH0Cu8I/XbYHc86JNKfPOsY0fOYYYXMPkh3xWRjFowp9uvYEqDnbmzV n4cxQjXQsYzH96soDHE45zKlaVP3R5SlccwC23Z8gzJSkIsl2vBl5ehnliUXK/BGNeL1 sdYd8SHFQHKs+vaRzegxhMI4B7S43efJDI8XcbtyAXSwGqZaLV+ruDuHU2YExdskfWjk pSIg== 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 :message-id:date:subject:cc:to:from; bh=LNJmuPhPv3f2gQqs5LJA7CUtxnPK4yIApGi/1aJ11MM=; b=0Qb+aCZoT6gFaOL2J2xIF7lMAVt66apXymNhw03vNUDvCIqaKT1b3Zve8w4F4lMUHI LFowkpQkQasStlU8UPEoQMOWTH79lHzlxA2rdmY0IKVuK6CizYO+U2Fl0LNNgSSxl/4A S1VbZ5/DbJfloeGLJG3rldGRxoWea2wBJzy0hG40XDWeIhJAyZa+ihhywPpLrbIcZvSL FhwmgRf4S/GBN5Fdpa50DL53irTsgJH+xTzbjqHjwyD2bm2kv4yb/S6viDSmABorxskc 3qAqn8M44s507ldpO0Ne2REDFk6RUL49L6lqfNDPh6vjaSVaB6uARORrOzWKM42aMymA L78A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 6-20020a630106000000b00372744cd486si3226711pgb.835.2022.03.03.14.21.03; Thu, 03 Mar 2022 14:21:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234149AbiCCOmm (ORCPT + 99 others); Thu, 3 Mar 2022 09:42:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234148AbiCCOml (ORCPT ); Thu, 3 Mar 2022 09:42:41 -0500 Received: from hust.edu.cn (mail.hust.edu.cn [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1CAA18E425 for ; Thu, 3 Mar 2022 06:41:52 -0800 (PST) Received: from localhost.localdomain ([172.16.0.254]) (user=dzm91@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 223EeT4P019337-223EeT4S019337 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Thu, 3 Mar 2022 22:40:35 +0800 From: Dongliang Mu To: Chris Mason , Josef Bacik , David Sterba Cc: Dongliang Mu , syzbot+82650a4e0ed38f218363@syzkaller.appspotmail.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] btrfs: don't access possibly stale fs_info data in device_list_add Date: Thu, 3 Mar 2022 22:40:27 +0800 Message-Id: <20220303144027.1981835-1-dzm91@hust.edu.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-FEAS-AUTH-USER: dzm91@hust.edu.cn X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dongliang Mu Syzbot reported a possible use-after-free in printing information in device_list_add. Very similar with the bug fixed by commit 0697d9a61099 ("btrfs: don't access possibly stale fs_info data for printing duplicate device"), but this time the use occurs in btrfs_info_in_rcu. ============================================================ Call Trace: kasan_report.cold+0x83/0xdf mm/kasan/report.c:459 btrfs_printk+0x395/0x425 fs/btrfs/super.c:244 device_list_add.cold+0xd7/0x2ed fs/btrfs/volumes.c:957 btrfs_scan_one_device+0x4c7/0x5c0 fs/btrfs/volumes.c:1387 btrfs_control_ioctl+0x12a/0x2d0 fs/btrfs/super.c:2409 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:874 [inline] __se_sys_ioctl fs/ioctl.c:860 [inline] __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:860 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x44/0xae ============================================================ Fix this by modifying device->fs_info to NULL too. Reported-and-tested-by: syzbot+82650a4e0ed38f218363@syzkaller.appspotmail.com Signed-off-by: Dongliang Mu --- fs/btrfs/volumes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index b07d382d53a8..c1325bdae9a1 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -954,7 +954,7 @@ static noinline struct btrfs_device *device_list_add(const char *path, task_pid_nr(current)); return ERR_PTR(-EEXIST); } - btrfs_info_in_rcu(device->fs_info, + btrfs_info_in_rcu(NULL, "devid %llu device path %s changed to %s scanned by %s (%d)", devid, rcu_str_deref(device->name), path, current->comm, -- 2.25.1