Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp4153098rwl; Sat, 7 Jan 2023 12:06:56 -0800 (PST) X-Google-Smtp-Source: AMrXdXtYnOn2bdaARdfRePVSb8Qljig2743z1IoDpm6c5WP+c6C/yJlhXf6tg1qwLX8WIdUbC+pp X-Received: by 2002:a17:907:73c1:b0:7e7:4dd7:bc0c with SMTP id es1-20020a17090773c100b007e74dd7bc0cmr48895062ejc.66.1673122016716; Sat, 07 Jan 2023 12:06:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673122016; cv=none; d=google.com; s=arc-20160816; b=GUx3sv1IyG7RV8JljHgTFaquKoQasV9V+Z1GLlj35uXQhpg9gffUzL/+pf1N8IjKOO 7IHY8Yv8mW0+ToLlVbaEdYnMDJAJABzcbNaIBF+j4jj8XNiQt8RJvLQ5z+mojTizKeE9 +u8klitGlwlL9CLGzWU/Sp2IwmWGW48/MJaj4pwcCtr/nw1Ie53CEwxo7/S8MTBR/4+m qWB+x1SREoAioD3SW2AbnD1StH5XeHdllUhtxexwJleHVR2Xf8xXUhIQLNXIz+UKCTdd 3Tk/G/CSFZX4fWevcE80e56tPFv2ptVhd1bcj5UD3ZvBlnXogk2MeU9wVLEq8iZnmzH1 l3Xg== 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:dkim-filter; bh=46Om3KozLAr4Twn7WH/XwL5S4olDBoQ+x1OHtQBj8fI=; b=GxlIakynDuZAd/2Di43kCtm4mzU3yTaA9C/UNAKp5cDbnh52E74oxzw4+xiU4k86lJ oOhXlXBfebOqfWPMUITN66K9whQFOb4AGp8kvOPdQmITXPFWHAcmV+8gV2AivlFMKWTk lrzaRqbIiPINmdFGkxKpK3OVhxmhX91mwYuY72Ff4j0vx6cbnDdSOxsoKABzUY5QxfO0 LSe9WVwbr7NscKra3TB19PO9vcspWvZVl5Vqdo0Y39z26m9bXypFbkqAD2ot1x7/VG5m bPQ/s8T4WfoPWaNeLX4FCb5sUcdrJ6jXbWWVZgVziskKCed3vSpG4FBs4h5686EhkESE csEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=nRW2dSWV; 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=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b18-20020a50ccd2000000b0046311e80ebcsi5562677edj.151.2023.01.07.12.06.43; Sat, 07 Jan 2023 12:06:56 -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; dkim=pass header.i=@ispras.ru header.s=default header.b=nRW2dSWV; 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=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232674AbjAGTuy (ORCPT + 56 others); Sat, 7 Jan 2023 14:50:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232480AbjAGTus (ORCPT ); Sat, 7 Jan 2023 14:50:48 -0500 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21281482AF for ; Sat, 7 Jan 2023 11:50:48 -0800 (PST) Received: from fedcomp.intra.ispras.ru (unknown [46.242.14.200]) by mail.ispras.ru (Postfix) with ESMTPSA id 8EE95419E9CE; Sat, 7 Jan 2023 19:50:46 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 8EE95419E9CE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1673121046; bh=46Om3KozLAr4Twn7WH/XwL5S4olDBoQ+x1OHtQBj8fI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nRW2dSWV2eWVdP0jogGl0ihZC4AGM9yxvUG0fCqtSamboh0hoilQ6jjhxEYJMryxV YaEpRcsBm9L/gCSrq7TgLUEUWaYAQ/ZSGJFea2xnLqmSlWh0rKdNh4mQ4yVivK2lVV ZKLUR64NIHEL9M8QpdIBNAaK6L5YoDyVuXvF+MKI= From: Fedor Pchelkin To: Jan Kara Cc: Fedor Pchelkin , linux-kernel@vger.kernel.org, Alexey Khoroshilov , lvc-project@linuxtesting.org, syzbot+8a5a459f324d510ea15a@syzkaller.appspotmail.com Subject: [PATCH 1/1] udf: Fix null-ptr-deref in udf_write_fi() Date: Sat, 7 Jan 2023 22:50:16 +0300 Message-Id: <20230107195016.290627-2-pchelkin@ispras.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230107195016.290627-1-pchelkin@ispras.ru> References: <20230107195016.290627-1-pchelkin@ispras.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 udf_find_entry() can return NULL or an error pointer if it fails. So we should check its return value to avoid NULL pointer dereferencing in udf_write_fi() (which is called from udf_delete_entry()). Also, if udf_find_entry() returns an error pointer, it is possible that ofibh and ocfi structs hold invalid values which can cause additional problems in udf_write_fi(). If udf_find_entry() returns an error pointer, udf_rename() should return with an error code. If udf_find_entry() returns NULL, ofi has probably already been deleted. Found by Linux Verification Center (linuxtesting.org) with Syzkaller. Fixes: 231473f6ddce ("udf: Return error from udf_find_entry()") Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: syzbot+8a5a459f324d510ea15a@syzkaller.appspotmail.com Signed-off-by: Fedor Pchelkin Signed-off-by: Alexey Khoroshilov --- fs/udf/namei.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/udf/namei.c b/fs/udf/namei.c index 7c95c549dd64..6b058c6ebf93 100644 --- a/fs/udf/namei.c +++ b/fs/udf/namei.c @@ -1170,7 +1170,12 @@ 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); - udf_delete_entry(old_dir, ofi, &ofibh, &ocfi); + if (ofi && IS_ERR(ofi)) { + retval = PTR_ERR(ofi); + goto end_rename; + } else if (ofi) { + udf_delete_entry(old_dir, ofi, &ofibh, &ocfi); + } if (new_inode) { new_inode->i_ctime = current_time(new_inode); -- 2.34.1