Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1852720pxb; Mon, 13 Sep 2021 06:58:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQPorILBdNJrAOdLU2KpW9eTmGmbr8L9n8D8UKj4LGF/P3aO6w9PJ7JAhyUHcZAZYq0LpW X-Received: by 2002:a17:906:368e:: with SMTP id a14mr12716559ejc.60.1631541497005; Mon, 13 Sep 2021 06:58:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631541496; cv=none; d=google.com; s=arc-20160816; b=j+HjOJcA949iOHj8+RrFZCkp14s+hrACvD3zaMs8KYZA32qeglRNdvbwPs4/bjO9ga NpIoAoBXEqQ5SNLi7ceGgZgCsWQL0Ltweuw6d60nZpHPvKcrVfggoABLEynDdnHf2YR+ fZSgBSOgI1SyOrW0cT9JD8Q3i2TD6KhP9FTjURWILVxsSn1C0RQ2a16rhp3gCwGdRFF9 RLabnm3EpCn6rkWG/neZQeSOCzATMysHqE7Y2DiMVt+8kFudtgDLaXr/JtCay7WCe5ks rovPIwVMJSBltYyoq8ntAr2HiCp1VeGRHhj7jWkP4lft9rN1X7pgNiWGC6+nisTeCtK+ 07bw== 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=usN/U5+rFT1FF6EByxIWuQoaxRh5l9lArerMrtWigfo=; b=YUEppTruC5eHlvMJUOeFXOt6aT7ETFb7VltqGbg/YDO9Ganj2xC0h5fqGPRTvDddnj RTj2jdSpvWlF3scQKpXmsnfjlRDkaVCGWknLhUA/Qg20aVdifXMKB2+GfZtsnCjAQTr6 8ePS7DWsJjfs69nMLcMoVNAip5/EBSSfhxL6aqZfD3/yuEuc4Htwe+41pWkwF/kleBB/ Y8VRiLSLpYajodlAv1vonfrc771tRS3l4QnCfCzjOgHIuGrfBkuUe0XPboVIggcE44Gn eOWQ9L6wTJcwtUeTr/3qftAQIDKgGQhVwF5cDLRlJ5z6XAK2GpOasdEVF1A8zgXBKKMo dMhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EtjHOo2K; 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 bx16si7641031ejb.146.2021.09.13.06.57.52; Mon, 13 Sep 2021 06:58:16 -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=EtjHOo2K; 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 S242093AbhIMN5H (ORCPT + 99 others); Mon, 13 Sep 2021 09:57:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:34746 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244494AbhIMNwz (ORCPT ); Mon, 13 Sep 2021 09:52:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CE38461882; Mon, 13 Sep 2021 13:34:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631540075; bh=K4uaTHapmH3U6xH9ucIb0nunIP0v4qwcdxnoKEqCHMg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EtjHOo2Ki1tkPVx9MxAeoGYFkTrpNvGjHUZQdCIK3rKm0kmmVIryg5aUv/fSvunOj B4E+SPf7YtAt5yjDaOoYBu8a7HZdOs59xjURzo9PjugIK3vQvUH+uEpDFKtM2lzYad zpOK3ci7g+IydEtOWWO60FD3tQnCkMBjdU7wP5j4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stian Skjelstad , Jan Kara , Sasha Levin Subject: [PATCH 5.13 040/300] udf_get_extendedattr() had no boundary checks. Date: Mon, 13 Sep 2021 15:11:41 +0200 Message-Id: <20210913131110.686493883@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131109.253835823@linuxfoundation.org> References: <20210913131109.253835823@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: Stian Skjelstad [ Upstream commit 58bc6d1be2f3b0ceecb6027dfa17513ec6aa2abb ] When parsing the ExtendedAttr data, malicous or corrupt attribute length could cause kernel hangs and buffer overruns in some special cases. Link: https://lore.kernel.org/r/20210822093332.25234-1-stian.skjelstad@gmail.com Signed-off-by: Stian Skjelstad Signed-off-by: Jan Kara Signed-off-by: Sasha Levin --- fs/udf/misc.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fs/udf/misc.c b/fs/udf/misc.c index eab94527340d..1614d308d0f0 100644 --- a/fs/udf/misc.c +++ b/fs/udf/misc.c @@ -173,13 +173,22 @@ struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type, else offset = le32_to_cpu(eahd->appAttrLocation); - while (offset < iinfo->i_lenEAttr) { + while (offset + sizeof(*gaf) < iinfo->i_lenEAttr) { + uint32_t attrLength; + gaf = (struct genericFormat *)&ea[offset]; + attrLength = le32_to_cpu(gaf->attrLength); + + /* Detect undersized elements and buffer overflows */ + if ((attrLength < sizeof(*gaf)) || + (attrLength > (iinfo->i_lenEAttr - offset))) + break; + if (le32_to_cpu(gaf->attrType) == type && gaf->attrSubtype == subtype) return gaf; else - offset += le32_to_cpu(gaf->attrLength); + offset += attrLength; } } -- 2.30.2