Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2564698lkm; Mon, 20 Sep 2021 18:50:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxpnyNlUZajJ5DppRU0mQD97wCI8accPbMx5eGYY+w4UFCz8QfcNgVRNa2f43wEecgqKjxZ X-Received: by 2002:a50:d4dc:: with SMTP id e28mr31355027edj.106.1632189033599; Mon, 20 Sep 2021 18:50:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632189033; cv=none; d=google.com; s=arc-20160816; b=Brl77cIqe2duNqu/Dyl7MhNGwOtt+1PtCzQQDaG/lpytjnx1pGAF8+DfN5KsXZD8cc dxOYBnMeFKYS5oVEvUSOirxxJ0QgE/ZUkCtn4MocFm3fmRNTsdjX/xYcIr1Koqz3entX WgFyBb+snMQoMlQB5t+1wfk6uJSxGxYTMsxLLGDkVeXHLzeJzPwXgHPRXsm6XR6QmVey tGDbp/LZ/Rj16U1cK/2ciKUePUIcZmXH8n72v/lwLN8jhtgFE4iVJ/IlwqpfF/GPwhEW cWTFxIvaw/Ef6BmXYi9MgTrbRvmGydmm1tUDr7TmSYcAomG7KZVa1qzigftJP53f0YZs hNog== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=55OpmlQx6CX4ideiS//3SXB/96/nawmzhdr01oKeFWU=; b=GROI2AJEP85v53vQv6lNpaZ5Qv/kjK+wsKaLWCymwnwB/9JjxsLF3m5kiDpbGQVjP5 se81bcgSBmj4xavdMZ8POuVk2gCKlE/jTaVU9cbKq/JfuAotFv/qjy3RBKrsV+ewjazn CpIGIHcjbzqhIZzie6nKKTghpC5upruSLzOQakGIdV8yLiTbRjx3H7LOF2x0GrSOzWXU dbCZsSSy8pf1Xpd8VGnU4EmLhknfFvZr9JMlqx9U5A35fxYrlCwnvg7l5f1InKLCPgZH h9Jpkga9stFfdXgjkX4GBi96rjeG2h0ysdipaEpdTZId5vQjnjorzyFuHYNno65Lanx7 YgIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jE63iUah; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d20si19346922ejo.520.2021.09.20.18.50.10; Mon, 20 Sep 2021 18:50:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jE63iUah; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348639AbhITRkG (ORCPT + 99 others); Mon, 20 Sep 2021 13:40:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:42360 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348712AbhITRha (ORCPT ); Mon, 20 Sep 2021 13:37:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5CABB61381; Mon, 20 Sep 2021 17:06:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632157615; bh=GQ9lV9zBSX7ryX4LY8y0KL8mtGf2KgywVURBNcGLNkc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jE63iUahRbbU19FaF35MCjSTkddgg0grvM4r/DAzlnYCMFJyFx5x0NEwly0AdNiif LyQ3Bt/YYcy84AaWon3PSB/mMdtdB2hNGXYwsjVHtKFWWj3rRp/CiM3Et3eaPZZlKj TSAMNaQNbugD2Clq+2TozMEV+NSlKn7QJ/WoKdOc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+7fbfe5fed73ebb675748@syzkaller.appspotmail.com, Jan Kara , Sasha Levin Subject: [PATCH 4.19 040/293] udf: Check LVID earlier Date: Mon, 20 Sep 2021 18:40:02 +0200 Message-Id: <20210920163934.647035360@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163933.258815435@linuxfoundation.org> References: <20210920163933.258815435@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jan Kara [ Upstream commit 781d2a9a2fc7d0be53a072794dc03ef6de770f3d ] We were checking validity of LVID entries only when getting implementation use information from LVID in udf_sb_lvidiu(). However if the LVID is suitably corrupted, it can cause problems also to code such as udf_count_free() which doesn't use udf_sb_lvidiu(). So check validity of LVID already when loading it from the disk and just disable LVID altogether when it is not valid. Reported-by: syzbot+7fbfe5fed73ebb675748@syzkaller.appspotmail.com Signed-off-by: Jan Kara Signed-off-by: Sasha Levin --- fs/udf/super.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/fs/udf/super.c b/fs/udf/super.c index c7f6243f318b..9c71246e6d60 100644 --- a/fs/udf/super.c +++ b/fs/udf/super.c @@ -112,16 +112,10 @@ struct logicalVolIntegrityDescImpUse *udf_sb_lvidiu(struct super_block *sb) return NULL; lvid = (struct logicalVolIntegrityDesc *)UDF_SB(sb)->s_lvid_bh->b_data; partnum = le32_to_cpu(lvid->numOfPartitions); - if ((sb->s_blocksize - sizeof(struct logicalVolIntegrityDescImpUse) - - offsetof(struct logicalVolIntegrityDesc, impUse)) / - (2 * sizeof(uint32_t)) < partnum) { - udf_err(sb, "Logical volume integrity descriptor corrupted " - "(numOfPartitions = %u)!\n", partnum); - return NULL; - } /* The offset is to skip freeSpaceTable and sizeTable arrays */ offset = partnum * 2 * sizeof(uint32_t); - return (struct logicalVolIntegrityDescImpUse *)&(lvid->impUse[offset]); + return (struct logicalVolIntegrityDescImpUse *) + (((uint8_t *)(lvid + 1)) + offset); } /* UDF filesystem type */ @@ -1529,6 +1523,7 @@ static void udf_load_logicalvolint(struct super_block *sb, struct kernel_extent_ struct udf_sb_info *sbi = UDF_SB(sb); struct logicalVolIntegrityDesc *lvid; int indirections = 0; + u32 parts, impuselen; while (++indirections <= UDF_MAX_LVID_NESTING) { final_bh = NULL; @@ -1555,15 +1550,27 @@ static void udf_load_logicalvolint(struct super_block *sb, struct kernel_extent_ lvid = (struct logicalVolIntegrityDesc *)final_bh->b_data; if (lvid->nextIntegrityExt.extLength == 0) - return; + goto check; loc = leea_to_cpu(lvid->nextIntegrityExt); } udf_warn(sb, "Too many LVID indirections (max %u), ignoring.\n", UDF_MAX_LVID_NESTING); +out_err: brelse(sbi->s_lvid_bh); sbi->s_lvid_bh = NULL; + return; +check: + parts = le32_to_cpu(lvid->numOfPartitions); + impuselen = le32_to_cpu(lvid->lengthOfImpUse); + if (parts >= sb->s_blocksize || impuselen >= sb->s_blocksize || + sizeof(struct logicalVolIntegrityDesc) + impuselen + + 2 * parts * sizeof(u32) > sb->s_blocksize) { + udf_warn(sb, "Corrupted LVID (parts=%u, impuselen=%u), " + "ignoring.\n", parts, impuselen); + goto out_err; + } } /* -- 2.30.2