Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2319143pxb; Mon, 20 Sep 2021 18:42:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9KfEXAyCS3/kf8l6NDAW/V87+hRyacYInFcm5ZXfycdrzsC7gi55/hhUgjY3cx5SVomhE X-Received: by 2002:a05:6e02:f13:: with SMTP id x19mr20067513ilj.216.1632188521514; Mon, 20 Sep 2021 18:42:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188521; cv=none; d=google.com; s=arc-20160816; b=nCBV7ljje4zUiQDKQ93Ye2M1x+tXKavkontSIG0NqXpTKCF8OTQpJpNGXiXTPzdCDD S7hIwOPHF37TueIlY7mPk2PrhgY0dfRMPDCyVY8CQ8ecJP2GabAhyEkraj7TWPIW/Fu6 3HhTGAWwv3Q7El5Y9Apt0vgZuHJdIiSQ7D56hABtwmRnpAoNe1WsqRZQeP68IlQPZzsS wmf4Qw/C0djR/G8NH8yFmb1J6/K7ZGr1EGcelN/g5bRidbpGyi3ZCzUapG6F+mR2/Ina i8A7O7cII/CHZgyd7Awro5pHabbt5gXnVJ7HbLYy7CZ3ZN6Jmvbk4CS61Q9GBd2wNN/6 eWAw== 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=9IzXp9j0pEqwDBNKDPBtqPTpmLR1ozNfG9ph+kONPiM=; b=dNG7yWpbJnFafWzkc4nhkWJoB8tPe4QXZoyl/8I2KacAPgfDOAS3/jAhjR1sWbC8j5 iHS0tCOZtpfaRwoVk6NbqoAUsm+1YwqZ1+pw+IqLJgquPOq6uWS2nwCl9EcnL2jJxNoC gMFwam4zece2PXdJIxmkJ8xeROlaUJda2sT4LxgOdpydzckB0T4gpTj0N0xIlbwBxPN7 6YlQL62r5ANszt2FJRCVGGO8UAy4JXXKKWS/sy2hg/f3F8bA+77dvUefumcdVPPqioZT S+CE39jpRBLeM/Qmv50pLgYdC8zZG0f7Lxyezc6QoKk32VctOs9s+MTpCzUJZ2ocJsNX Wbog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="OOF/O70f"; 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 k34si2981448jac.46.2021.09.20.18.41.50; Mon, 20 Sep 2021 18:42:01 -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="OOF/O70f"; 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 S243835AbhITQsa (ORCPT + 99 others); Mon, 20 Sep 2021 12:48:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:35830 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243426AbhITQrv (ORCPT ); Mon, 20 Sep 2021 12:47:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6A5A960F38; Mon, 20 Sep 2021 16:46:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632156384; bh=ygTgi3ZOuywsl37Y3rfKuIb8lCI6FVLBpXonPSgzYwY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OOF/O70f4lAM72sbo3MNxMFs49aH4yObQQ4r2KzTZnKWkfhk4Xuev/LscZf2hseqa jVaHkuMMEBFOKCBLCif9VNlmOHcvpxl7Y70lF47cCBRw8bVaWJz88oPlfodu68Cydr jsExIvKTqWnS/4SzKXJGBvi32ITiuyrDXihHgsSo= 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 4.4 035/133] udf_get_extendedattr() had no boundary checks. Date: Mon, 20 Sep 2021 18:41:53 +0200 Message-Id: <20210920163913.771559949@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163912.603434365@linuxfoundation.org> References: <20210920163912.603434365@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 71d1c25f360d..8c7f9ea251e5 100644 --- a/fs/udf/misc.c +++ b/fs/udf/misc.c @@ -175,13 +175,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