Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3407068rwa; Tue, 23 Aug 2022 04:22:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR4hKcBaz+87wb+RieaIRvRbtAi/QnHSXLsy3E8VPtWnaa3qw29lehRtzmaIiNgayOAotz0e X-Received: by 2002:a65:4d48:0:b0:421:5af6:9278 with SMTP id j8-20020a654d48000000b004215af69278mr20463680pgt.1.1661253768997; Tue, 23 Aug 2022 04:22:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253768; cv=none; d=google.com; s=arc-20160816; b=sesZQ8nGkNS72a8onI6WmfBywsziZqAZrCT+TsUxSBf33eXx2UlVVGoZpxX0kZ+A4Z SUfxNtczjCHHu4zWPe4QYP/toUAZ4ETXU0shoq+sLBwydLGB5b9f7o1/ebXz5vCNxnly uLTmmD1bXvZ9PGVhDfErCYl0E24iwyKDw9r1elu9lDIUCdeJ/UmIj9O+W4RkFZrJ8G9f vpO9mxG2X9SUTDOOQ4gAWs++utYTwL/AT7a1h4qbQBuoHb5SoYdsnFi/qddBb4in6+9T tzPftIFqQWfghu/E077AqFJ6TIdJ+3ijHGC8PY6OGFn5Ld2ax8acBcNXnyzeQo+pzG91 VYvw== 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=dr/xzTyTpiE494x7eUVyL0QQqWBmY1hm1Mzmbu+UcC0dvPHcVKgsl56bnn+Gug7zFq Mu5ElfBpqZ7Z0+rsu8eLyNHc/fiuGNVfoXaHv1yy5eo70fh8yK77JOkUunMccllaUbFU J+gHEYK4qBIAGM0HSsLw4VcohoBFtj6dokWKK8RhfoUp6Y1J8BIhcbgyyf4jDZnOvrXd nna1PGmms92fQNgFFmjkt6qk0SPEX3eHcE5V0GlQXDhRDC6DVZYJ/gUZAC++FAVABQuO kAAUdwDUUHcIbIfLivLZRePpkr9s+ffgedOomNAYva4lHRQLcLhZNydbgwN0ehDDgKGw nA2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dDpkDa1Y; 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 r136-20020a632b8e000000b0042a00292790si13542733pgr.242.2022.08.23.04.22.38; Tue, 23 Aug 2022 04:22:48 -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=dDpkDa1Y; 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 S1356092AbiHWKtE (ORCPT + 99 others); Tue, 23 Aug 2022 06:49:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356438AbiHWKmR (ORCPT ); Tue, 23 Aug 2022 06:42:17 -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 BB4F3A8CE0; Tue, 23 Aug 2022 02:09:39 -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 BA3BA6010E; Tue, 23 Aug 2022 09:09:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C214DC433C1; Tue, 23 Aug 2022 09:09:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245778; bh=xwMDHTFnMLKH4+U7KF18c69Qbn3zdxCc6asbHfolpLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dDpkDa1Y/tAn/3zU5WsTN59/EcLRsH6Q7pO/akzFjJG7k6/RP527iD8Ox6WOPPobK rxp3MmkELzwUiAeVRqHcW/f6D8wuF7cBYc0Txfb7DvJbzSUpM8/BzHmGTMwG2OQEmk EEYp4j2pfXq0PVY49nsC1pdg9TEDxpvYoqtU/194= 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.19 187/287] ext4: add EXT4_INODE_HAS_XATTR_SPACE macro in xattr.h Date: Tue, 23 Aug 2022 10:25:56 +0200 Message-Id: <20220823080107.100935223@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@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;