From patchwork Tue Nov 8 02:27:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 16798 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2426045wru; Mon, 7 Nov 2022 18:05:13 -0800 (PST) X-Google-Smtp-Source: AMsMyM4mkVQI+i2jqbYBZI60Vim4d6L7xWLEYX4GE/T71cxbOeZoJzoLQBh6JB1KIpaUPeO4GhYJ X-Received: by 2002:a05:6a00:2906:b0:52a:bc7f:f801 with SMTP id cg6-20020a056a00290600b0052abc7ff801mr54490724pfb.49.1667873113561; Mon, 07 Nov 2022 18:05:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667873113; cv=none; d=google.com; s=arc-20160816; b=1A2dwzIWCu7mocw/KATNH5k/m5C4dxM8D5gtbUZF4rgW8K3k2hginrQooettoLSy94 BRzE8vKxMlHyIdeLe7sD3rUiE32s/POtNc/rAIwZgmIZTAZqpR9sjO88TQa/iJpuGWsB IIJvYkqHgJ8lCXVdmo7Dt08MaaSy6/J9D5iVSs6hx2ignT7cGajVf1Ilpxy5PLW36X58 NqgtnkBJEQpGdfWQF+riQsaandxfAAyJIqZC6E6R4YpQyBgSlU6gRl78q4sI9ZpWsNRM RXCRA+BuPY/EG31+Twr80AJbnQ3aRs42kbWCZN8U5MEO68lD5XoAEDWhQlNCzDVVANoF ZjMg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id iw12-20020a170903044c00b00186ab03eebfsi12491111plb.418.2022.11.07.18.04.59; Mon, 07 Nov 2022 18:05:13 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748891717761689046?= X-GMAIL-MSGID: =?utf-8?q?1748891717761689046?= 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) {