Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp49459pxb; Mon, 13 Sep 2021 12:36:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVf2KihmJo37+nIj88CAkUg/l7iD/ba4OM3FUpa5z7wYceCzhQSoRzOmE83mH/COqstLGx X-Received: by 2002:a17:906:269a:: with SMTP id t26mr9641249ejc.20.1631561770944; Mon, 13 Sep 2021 12:36:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631561770; cv=none; d=google.com; s=arc-20160816; b=06DnZEW+7lqemSeqG/B6258NV/0U5giW3WGL9IdEaht/taxNHCn2I9+DG6V4uXUS8I k6sVpII88C2kvgKBTUdWrpE35cXhqE/76A5z5QJmXIlWMzGuAovZJCT7Po9OkKF2fdO6 4SyzFZchrF/U8eRoUN5H3PAV+/3Y1FVSXZo6JbR1QwvcYgOjw6Go8wWYRgv8V7OrYY4d cf2xGFUxniozUpUMXjXmN74PfQXnapvFgrxYtgyyECNLL/Pn8vTmnmxOajshHWdLKOdq iqL8Zhu+1Rq1/42Wh7zvf4ZpXXq3qloxwLOxX0q3sRTgEQLvU2QILWsjso8Zn53iK1T0 CmLQ== 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=OU/xVq4xH3gNbF9qQO16FJqYBYkgKttTR0s2V8Y6OU1V996uRmCG35Bi9i5zpf0h0w N8qjY7j7iwwJrOXGWwYUZX8UQV1wp9wa1CDp5VA+HzRmqjwemTYJVgIHh+iUgbs07uie ZvKjzyoTlnv+wCLNpWRdCIl50jWH59Hap97gzsjMwOHTmt6rUPUdJofxPMYsaAkDShpi SINSkifAcbPypTHeaNQxz9fzZn7CS+x76ogsOIwx1go5aAyfPSkzBCCKgYuqLKpvcjrq z4LuZpFROUpcU68izuKC2OA64gKG1dwvJ3c40wU4iH67Lcy2VWWT92JB5f1be1kvFE02 LYug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=E8ISyucb; 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 z4si9555534ejl.76.2021.09.13.12.35.44; Mon, 13 Sep 2021 12:36:10 -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=E8ISyucb; 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 S243130AbhIMNiT (ORCPT + 99 others); Mon, 13 Sep 2021 09:38:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:32892 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242657AbhIMNcg (ORCPT ); Mon, 13 Sep 2021 09:32:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7623461371; Mon, 13 Sep 2021 13:25:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539547; bh=K4uaTHapmH3U6xH9ucIb0nunIP0v4qwcdxnoKEqCHMg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E8ISyucbLqiHBB5kgERP4fcuUu+MmlAe0wqD5bYdqb+PuFViQHkHX1jk8G2HfNXt9 TLule9q87E4C+optiVPvkjMhQKvq6P6NBbGngcsWB9pczH9KuwAlS6vmaXLaY2c7TJ hzHZ9pUXYZO47Aq4JsHL72PgGQ0C9z06C/e9M/TU= 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.10 034/236] udf_get_extendedattr() had no boundary checks. Date: Mon, 13 Sep 2021 15:12:19 +0200 Message-Id: <20210913131101.500259577@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131100.316353015@linuxfoundation.org> References: <20210913131100.316353015@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