Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1885429rwb; Fri, 19 Aug 2022 11:03:32 -0700 (PDT) X-Google-Smtp-Source: AA6agR76pEsR3f/JqSdroWmu07rBLJP4S2YLNcirO1VSoKjPgnnGxpNX7ie3jIM9Aqv6vL748uCd X-Received: by 2002:aa7:88c8:0:b0:536:926:700f with SMTP id k8-20020aa788c8000000b005360926700fmr4832644pff.72.1660932211735; Fri, 19 Aug 2022 11:03:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660932211; cv=none; d=google.com; s=arc-20160816; b=ULxExL+f60tlI9QGa/oC1Nyy5fAadUQRsc05QfBd68agCCktQv5+ku8wgq/G3Gz43c N+QNZ5kQRsqASOMW0qQIHzZpDvOMG5E8ugC6psDv0PIkV3GH7x2Cw9FgHk9d3podOFR8 O8AxnGjrQrTz5/GyqOn4Bytowhv78EhiJExX+v2AYLKOrtB/lhSgfolp5Bj5pQHLy+j6 CTGUaF9bmwtG6S0o1FMPXmF3p6WbszkmgoAiEBwnrAv2OUtsVdzea6I3BaGelyNXXAlW yJ6FELmdd8X+S233iozboek+neEAbXpEAddmXomsK4KecNkpMGjd85upKxLyKlZpogYP W3Ig== 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=aEhwjqnstzm+q6tTZ7zs6HhB+QRHzxb6+HXBCK6TX6g=; b=Th0asP2LljX1ewqS3vBi/kecw9EJgAh3LoQmKfgCrh8ASbF1EPNOaqcbBeO13fQhBW TsM+7EqOk+6is7Jp04HdzmHTnbBXOxjediXX+SGMv6vl+plQihKr0yxCl1hKKPoTdXvR z9jw9uOE6C8/EyMkwh7i+KRLFcR1/joPnLsVzFWmwCQCqtK3o3kEyXh3x6xM09ByGKqs fxTPSbwFUJGOl1P0WzANk6GwkAqs8uj/OrYeKbvE99ccOVJGenCu4GBOQskxuqXgRDYp 0Htr1cQTp8IOE6RWIg+0okvBAxEDKAqdNEp3U2HyZvSGKu03DA3N622j2Ktk9YFsA8Ik PpWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Tc/TYN4V"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m2-20020a170902e40200b0016f007ecddbsi276053ple.66.2022.08.19.11.03.20; Fri, 19 Aug 2022 11:03:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Tc/TYN4V"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1354000AbiHSQt5 (ORCPT + 99 others); Fri, 19 Aug 2022 12:49:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354132AbiHSQsJ (ORCPT ); Fri, 19 Aug 2022 12:48:09 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8C4F12C7EA; Fri, 19 Aug 2022 09:12:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id CD073CE26AB; Fri, 19 Aug 2022 16:12:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0D22C43149; Fri, 19 Aug 2022 16:11:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660925519; bh=xwMDHTFnMLKH4+U7KF18c69Qbn3zdxCc6asbHfolpLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tc/TYN4VXcCyQKuixKrWT7JvaoaDSscQ3/T/owmMjP0tUUcnwZhC5Xixi4qrp2VIz 2BIqp6u3t7SLepNxQi2xXwH7Wrmj3jRvIHLkxxDPVy/4sITA4ONCztcbUAh3FArCiY kb5f4ybFfdk1LfmknOKr8lRHNX++U8kQGZubxSyA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Baokun Li , Jan Kara , "Ritesh Harjani (IBM)" , Theodore Tso Subject: [PATCH 5.10 517/545] ext4: add EXT4_INODE_HAS_XATTR_SPACE macro in xattr.h Date: Fri, 19 Aug 2022 17:44:47 +0200 Message-Id: <20220819153852.662298440@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Baokun Li commit 179b14152dcb6a24c3415200603aebca70ff13af upstream. When adding an xattr to an inode, we must ensure that the inode_size is not less than EXT4_GOOD_OLD_INODE_SIZE + extra_isize + pad. Otherwise, the end position may be greater than the start position, resulting in UAF. Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Ritesh Harjani (IBM) Link: https://lore.kernel.org/r/20220616021358.2504451-2-libaokun1@huawei.com Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/ext4/xattr.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) --- a/fs/ext4/xattr.h +++ b/fs/ext4/xattr.h @@ -95,6 +95,19 @@ struct ext4_xattr_entry { #define EXT4_ZERO_XATTR_VALUE ((void *)-1) +/* + * If we want to add an xattr to the inode, we should make sure that + * i_extra_isize is not 0 and that the inode size is not less than + * EXT4_GOOD_OLD_INODE_SIZE + extra_isize + pad. + * EXT4_GOOD_OLD_INODE_SIZE extra_isize header entry pad data + * |--------------------------|------------|------|---------|---|-------| + */ +#define EXT4_INODE_HAS_XATTR_SPACE(inode) \ + ((EXT4_I(inode)->i_extra_isize != 0) && \ + (EXT4_GOOD_OLD_INODE_SIZE + EXT4_I(inode)->i_extra_isize + \ + sizeof(struct ext4_xattr_ibody_header) + EXT4_XATTR_PAD <= \ + EXT4_INODE_SIZE((inode)->i_sb))) + struct ext4_xattr_info { const char *name; const void *value;