Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3426043pxf; Mon, 22 Mar 2021 06:16:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6a2zTFktXYjQBWmnquqWuB1LrqzUCUeDCUd6eUx1AAiXJ8DPXjqv/18cE5taWy083vg3c X-Received: by 2002:a50:fc94:: with SMTP id f20mr25655257edq.370.1616419001376; Mon, 22 Mar 2021 06:16:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616419001; cv=none; d=google.com; s=arc-20160816; b=wxeBsvAxAVMLSD5cxZp8n5bNp8RopCIjur5tXSZdHeVidIDuU+zVAYRI+yCEA7g+cW YOkE6/5cPFYzaZdH3J+nqJ1/GjaYlkiAS7I3eZbRglfFzrBcBRLR+63pkSrTUDrXoOB8 1TP0VmC1AOf4WWzXvsdkkUZZWpbVRsmck4WGP7tjXNWQE/C1C2ywtH56q4mXv9yNX8WE VCumtTsAEVHZDB7X5wPNgcTZlP5/4nbyaV5tDF/7EOYGXUDWQZCrqePHqNrrJzvr7eJ1 GKSu8biYJ8LwAci7TODg1Tohv+IVNrnaH19w3JuPtKC24q3y6Tvt5wX0MDqNGiQekrM3 bNlA== 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=ymiTkKdsRieVuYLiGU2TkpQvqKGxzBcyuuZGNS4f2C8=; b=LAqjw3nV7b7qhUfYNAqSIm9BZTawyCc6INJ50wktwQi5RukTXrAM8bwSAXus0YxaeI 8sJdijhuEScbGDGS8zKV+0+sIydE+sJntGt1DpZrA3uqarob4ePKrwsWTPFpYk9EAQQX UoomJQa461fjtMZiIlycZP1HxC1e8hvxwL8QVYQ30ae958md02qT+VV0VQDqhPYFvSp2 4ZaYNuVP4pyySfedrlRG40ZKWQgKUG+QHg0GdIs2HBnwd2vuluDsXFp/GTVO0sJ+0HDF tLuFH//wmJJIoQsmQrTa2TLK0Cr021A+9TuczOPWcQ4nwlVJ6pvJjNpFPOBc2DfX2UDo cOTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="FIF/nQnS"; 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 hc31si10831875ejc.524.2021.03.22.06.16.18; Mon, 22 Mar 2021 06:16:41 -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="FIF/nQnS"; 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 S233131AbhCVNMY (ORCPT + 99 others); Mon, 22 Mar 2021 09:12:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:50516 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233094AbhCVM5o (ORCPT ); Mon, 22 Mar 2021 08:57:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6AF96619BD; Mon, 22 Mar 2021 12:49:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1616417356; bh=cTZ4pKqI4MOnC74+1p5ARE2mS0vr8FtJauf9yIXiEmI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FIF/nQnSVQcvHftJS9haZzEsXWh6l/9HUTSJoZ/UBxV/i0MyqyntSwaSW1+aJAnbF GRsjzbZx6WtUeo3+DtkOyCFkDaLxhGL4j3EQ9gcC4CVtbUOb4608Dj9EeJjFII4him u3nGIkNCum2V2zC041iqFpHqSngZXOkykJlzTZLQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+98b881fdd8ebf45ab4ae@syzkaller.appspotmail.com, stable@kernel.org, "zhangyi (F)" , Theodore Tso Subject: [PATCH 4.14 41/43] ext4: do not try to set xattr into ea_inode if value is empty Date: Mon, 22 Mar 2021 13:29:22 +0100 Message-Id: <20210322121921.355615556@linuxfoundation.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210322121920.053255560@linuxfoundation.org> References: <20210322121920.053255560@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: zhangyi (F) commit 6b22489911b726eebbf169caee52fea52013fbdd upstream. Syzbot report a warning that ext4 may create an empty ea_inode if set an empty extent attribute to a file on the file system which is no free blocks left. WARNING: CPU: 6 PID: 10667 at fs/ext4/xattr.c:1640 ext4_xattr_set_entry+0x10f8/0x1114 fs/ext4/xattr.c:1640 ... Call trace: ext4_xattr_set_entry+0x10f8/0x1114 fs/ext4/xattr.c:1640 ext4_xattr_block_set+0x1d0/0x1b1c fs/ext4/xattr.c:1942 ext4_xattr_set_handle+0x8a0/0xf1c fs/ext4/xattr.c:2390 ext4_xattr_set+0x120/0x1f0 fs/ext4/xattr.c:2491 ext4_xattr_trusted_set+0x48/0x5c fs/ext4/xattr_trusted.c:37 __vfs_setxattr+0x208/0x23c fs/xattr.c:177 ... Now, ext4 try to store extent attribute into an external inode if ext4_xattr_block_set() return -ENOSPC, but for the case of store an empty extent attribute, store the extent entry into the extent attribute block is enough. A simple reproduce below. fallocate test.img -l 1M mkfs.ext4 -F -b 2048 -O ea_inode test.img mount test.img /mnt dd if=/dev/zero of=/mnt/foo bs=2048 count=500 setfattr -n "user.test" /mnt/foo Reported-by: syzbot+98b881fdd8ebf45ab4ae@syzkaller.appspotmail.com Fixes: 9c6e7853c531 ("ext4: reserve space for xattr entries/names") Cc: stable@kernel.org Signed-off-by: zhangyi (F) Link: https://lore.kernel.org/r/20210305120508.298465-1-yi.zhang@huawei.com Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/ext4/xattr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -2418,7 +2418,7 @@ retry_inode: * external inode if possible. */ if (ext4_has_feature_ea_inode(inode->i_sb) && - !i.in_inode) { + i.value_len && !i.in_inode) { i.in_inode = 1; goto retry_inode; }