Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2789466rwb; Mon, 7 Nov 2022 18:31:54 -0800 (PST) X-Google-Smtp-Source: AMsMyM7HyGkmQ1RLhVJAhuPdWfSpKSWpLR2Cp+Mx9FaiwIfzJuzL92sci1czWlI8a7D8S+znlpGT X-Received: by 2002:a17:903:124c:b0:184:cb7e:67c5 with SMTP id u12-20020a170903124c00b00184cb7e67c5mr54373675plh.117.1667874713877; Mon, 07 Nov 2022 18:31:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667874713; cv=none; d=google.com; s=arc-20160816; b=Cm1HuoP+oSlspv/yGqawbTJFLN96ynFW665o2FsWznJpW6Vs0rxcHLl8B4ggkVOWLC oWH8gKEwD15Jl9OBW5JqQ00OANjseeC2El2MJJeKCpkszkKo2PUzKSWoWZQPSGyaZzT2 iuIPFdpW2ZpJVopK/5g8ZR1dg1cQIc9KSTarlrSL+9NzO4sdXa9w4qhX81mRoF8ccQaT VEj9oQTm+2qaCss41B/rIanlCaq3x1t6DFMEiO7B0xINVMVGw6OvvYQzmxpghjvjc9CV KA9LjWBH3ejw7Pc0vzBzJgUPu6oEiqJWREKRk6VXWO3veJC1k8nLvHJq0QiEFi2T7Q5B soHw== 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=D21tFF6fHIIRwgfRZyNvmqxk5U4Ev1tNoLUhg2D7aec=; b=cPK5ZsKzHL4zeKGQr6SYGPxo1JJ9aX/VInLxyqn+N9QZXtB4ux48pd4qHYa3D/IPN2 ohMWTfdfHvQC1I2igoEr/tNze/n1+tt+WGXw/BLhNDrs2macUjnET75aRxcrhE+Flrsx qqTiYQPMyukA90Azoim+HSmX5mO4YIf3gf+HcESG4uu2NQUddYAVbjUUhQhA3KLkuik7 sAr3egye/s4JXthGoQzFbzdiaEH0ebLVEeMekBsSSyZOqCZ+gv1/J1LmSpiKMJBU0W3l dKhNI+Qokwf8VTFKtIWByftqZN7OiRpEwY45VxEheyVu5h7UnmEXbwRvXwiCpY5DemC7 S6cA== 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rm11-20020a17090b3ecb00b0020addb2c6e7si15672289pjb.85.2022.11.07.18.31.42; Mon, 07 Nov 2022 18:31:53 -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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233360AbiKHBjo (ORCPT + 91 others); Mon, 7 Nov 2022 20:39:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbiKHBjn (ORCPT ); Mon, 7 Nov 2022 20:39:43 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E557186FF for ; Mon, 7 Nov 2022 17:39:42 -0800 (PST) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N5rPK0LYHzRp63; Tue, 8 Nov 2022 09:39:33 +0800 (CST) Received: from dggpemm100009.china.huawei.com (7.185.36.113) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 09:39:40 +0800 Received: from huawei.com (10.175.113.32) by dggpemm100009.china.huawei.com (7.185.36.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 8 Nov 2022 09:39:39 +0800 From: Liu Shixin To: Jan Kara CC: , Liu Shixin Subject: [PATCH] udf: fix NULL pointer dereference in udf_rename() Date: Tue, 8 Nov 2022 10:27:41 +0800 Message-ID: <20221108022741.492573-1-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm100009.china.huawei.com (7.185.36.113) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 Syzbot reported a NULL pointer dereference: Unable to handle kernel NULL pointer dereference at virtual address 0000000000000020 [...] Call trace: __memset+0x84/0x188 arch/arm64/lib/memset.S:98 udf_delete_entry fs/udf/namei.c:577 [inline] udf_rename+0x47c/0x6d0 fs/udf/namei.c:1173 vfs_rename+0x59c/0x7f8 fs/namei.c:4756 do_renameat2+0x490/0x758 fs/namei.c:4907 __do_sys_renameat2 fs/namei.c:4940 [inline] [...] Fix this by check return value of udf_find_entry() since ofi may be NULL or error code. Reported-by: syzbot+17fcf98a689ff64f669b@syzkaller.appspotmail.com Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Liu Shixin --- fs/udf/namei.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/udf/namei.c b/fs/udf/namei.c index fb4c30e05245..e0267e72cebb 100644 --- a/fs/udf/namei.c +++ b/fs/udf/namei.c @@ -1170,6 +1170,11 @@ static int udf_rename(struct user_namespace *mnt_userns, struct inode *old_dir, /* The old fid may have moved - find it again */ ofi = udf_find_entry(old_dir, &old_dentry->d_name, &ofibh, &ocfi); + if (IS_ERR_OR_NULL(ofi)) { + retval = PTR_ERR(ofi); + goto end_rename; + } + udf_delete_entry(old_dir, ofi, &ofibh, &ocfi); if (new_inode) { -- 2.25.1