Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp5734pxb; Mon, 13 Sep 2021 11:27:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqUZpCsV70cjnJtgY+jywd4gKWEP7ag4TIKND4EWmqMxh4iSXUGXheYlX2AD52V+p0cCON X-Received: by 2002:a6b:e50e:: with SMTP id y14mr9970114ioc.54.1631557634424; Mon, 13 Sep 2021 11:27:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631557634; cv=none; d=google.com; s=arc-20160816; b=f/OIK5yUcvcTvvE9RgwZyGQcsz9Q0Rm5qA1NmkrZJ2FmJYSOaJWI7FNp9kKu1FrtPo xr39d28FqDiXYPT6GXgcbeITj1V/TUP/nanBG+M1TCp9O6JMvoPtp9axmA58502BeO/x iSgKw9PRflFoPLSlaszV+mH+VO2nT2ifrUntng7G0S0nbNCYG4LD40tn5z5a24zFf3Fc +soDLdqCuhsiKpFv+xBbfvv46QSkfGipTNBr08HTzNOrKf4CwwSGjzkrgpSoA9T+Mlgp wg5dZ9sZs9cpqAUtcmNrgXfL+qwMmDgAxD3D8Z0IzUQAEeSZilOiTZbVclW/NxTmwHw6 aSIg== 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=5ss21kwXHfnnLkrxGmuCvLmR0aQLe/DoBJ1aztKpNt8=; b=m2Nt3N33LVgtaxaLn5FmiRC9zWT5EZpIxd3YZyfHfXOaLbrMJZCU23btz2zAPLTbWK pwe4AfIr6sI3SLcwou/hhlMl4GkiarGDVSNf22yp8F3TYEZGbAuMcO0uRyeDCV0V2NWA 1BE6gtiMgM3yXSLMCB4TavZruONWdRGK9SIjz0l7m4ZaS9ZEmydEnWG2mYHzOIiyxwgI EQeI2c8gQlPi1Xp9d/117lfWvCJNOKBAeyTJwN2WYk+JDxscwFhWvEj1Zvs7OMlk/FlH 2CB5FVfQ6Pr1+nS5B/WbrzoH5QyJclrDlfiFJvUy1FdHg+8EsV99TeZuJrJZ60B0hAGJ Letw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="G+PC/lIW"; 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 b184si7756575jab.61.2021.09.13.11.27.01; Mon, 13 Sep 2021 11:27:14 -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="G+PC/lIW"; 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 S240647AbhIMNWV (ORCPT + 99 others); Mon, 13 Sep 2021 09:22:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:35046 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240535AbhIMNUz (ORCPT ); Mon, 13 Sep 2021 09:20:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B15A7610D1; Mon, 13 Sep 2021 13:19:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539152; bh=E3trja30u49PQGxLI5iO0/3F9tdhTe9oBxHfSyclHs4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G+PC/lIW8syzVV9vjz2vb1lemFj3zfSLJJUtnqndbN3d0GD6f1f7mr5QHpMr4BAno RlkoxHmXSVFZCWkARsjc24TEVKu52iQGj+kzrhYfrREHxYQekK5CHyHuJLPhEBtfcB d+3yWyhyKrj/FNRU2Ed4EGqqQxL3VF3xcXJkTQis= 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.4 028/144] udf_get_extendedattr() had no boundary checks. Date: Mon, 13 Sep 2021 15:13:29 +0200 Message-Id: <20210913131048.890671207@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131047.974309396@linuxfoundation.org> References: <20210913131047.974309396@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 401e64cde1be..853bcff51043 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