Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3413611rwa; Tue, 23 Aug 2022 04:29:53 -0700 (PDT) X-Google-Smtp-Source: AA6agR5V7H2y/vVsYPDSsNXBT56NWWDoxjAwFGsppfOCM16pS9panPyZFxyYNMLpbpv4W9sgSFdL X-Received: by 2002:a17:907:75cd:b0:73d:8d05:1b35 with SMTP id jl13-20020a17090775cd00b0073d8d051b35mr4396025ejc.638.1661254192911; Tue, 23 Aug 2022 04:29:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254192; cv=none; d=google.com; s=arc-20160816; b=wF8NxRy2yBsLS+zifmBZmsCBEa9clO16iXC2YDQPTI/X/2A7cItHod8v6+kckeFNVR MjdV4W4Bk2z3WthjkaaxHA4a4aTqjkPXvrDtYbkxUhTTb6PEHO9WvhhiXk4cOZqgSq8U or9+DGln3Fd53QTWI2wezKbX/Owp0DhzZ3z02Eqyb6JQsZ+WGGZYCRCb3b/TZDar/UJt eS/vR88rphkG0B+95mHV47BkxVup6/xWhc7GD2VRJAUhQj3RaxKOhHQyqc5BtbeKxFln gjMM4X4ihrcTiIQeuq/b1pgThh3suN7NpevlL/zucC7P3BF7wr/ajj/MhBC/eeWJktyt lMGg== 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=IIY5NhhuZOAhufqT7QfMAUrcEyiHCVJB0ow1jpIFxo1LZ88hYJH6e/Wj8fYGKfFSbG uEYkyY//8R2GY9JO2QFJSNfmB2nWEYedX9pOYlY7PWVt8MPoV7ajpub0xbl7OC5rLaaR EYMLHeMKLNXtUVPKtj4UFjDmVPzyUhto11LLJ3jPZpj730jAKYnKyFwcfzw6DskCCSkk hGtLf5UugptjLl9uXZmABBR1Om1kpHmSEN56jg8Fc9DYxGbiRMd+T7vABRCo++VgRdgQ UEQl4/h/rMX2ao5nLo9aNE1Yek+ZvyV3X6atYQZnsfh96q26Ww678MhX5hRHFUcqFr4Q yPEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=L+O1h4so; 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 a13-20020a50858d000000b0043cc3404d7dsi1745544edh.84.2022.08.23.04.29.26; Tue, 23 Aug 2022 04:29:52 -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=L+O1h4so; 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 S1352710AbiHWKGI (ORCPT + 99 others); Tue, 23 Aug 2022 06:06:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352210AbiHWKBW (ORCPT ); Tue, 23 Aug 2022 06:01:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56210491EF; Tue, 23 Aug 2022 01:49:01 -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 dfw.source.kernel.org (Postfix) with ESMTPS id E57A861386; Tue, 23 Aug 2022 08:49:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D16E5C433D6; Tue, 23 Aug 2022 08:48:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244540; bh=xwMDHTFnMLKH4+U7KF18c69Qbn3zdxCc6asbHfolpLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L+O1h4soKm8xnkdjVbxazgIsv7qfOe8CKsElg++CN70Ck0lzi+laQyxlvC9uRIc9+ p8bj7fGN9CB87IH6+oRyn3GWz22IUALZqxpRq50BK0xetVpqG+mCgmdydMAHwPESt8 qxTlVJNNB+oks0FFZUTEi17uCmkqd5gTi6iVvEFM= 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 4.14 152/229] ext4: add EXT4_INODE_HAS_XATTR_SPACE macro in xattr.h Date: Tue, 23 Aug 2022 10:25:13 +0200 Message-Id: <20220823080059.101216471@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080053.202747790@linuxfoundation.org> References: <20220823080053.202747790@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;