Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1028125yba; Thu, 4 Apr 2019 02:46:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqwYblRnuWY956hYhKjmQxn6FedMXw/w5CvSoCrUBgR9dkEgfbtsCrNdunlhDVGPPt5kk4/G X-Received: by 2002:a65:5941:: with SMTP id g1mr4953989pgu.51.1554371183292; Thu, 04 Apr 2019 02:46:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554371183; cv=none; d=google.com; s=arc-20160816; b=EsLAu0Z5KDl50F9ILpAq5fgqDaZzw+Pe81lLmlf8+Wep7IXR4jtVKyefhHCP5PFAE6 UCRQaJA0RAmZaIQ/EDbeoqpE/dPlzbGk0gxUB+tifjKVHyURHs6f2AaU2S83yuf4C9Yp 2+/SaHpXeChP76BgKlqeECQjxoP+Nw2EEtw6VwgOHpnbz3B63FOPRxehcKdBqbxBrO2m xpgcG6GuLew1cDc8ipr7dMnuc2gTxQT4QE9q3hvjAUWkLB7frm5FxzlNWufXIySwYGpZ NZVfa5nkDf3uortGXrkTiTCEhRW//EkwTYMqVO9Ly9QCcmhb2vA7YcEiPwIDzsac8JXw IeHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+2uIK8XpxayivR62pMb+LR+CoPo47kxR697uLkmsB28=; b=yKozFZAJv8AR7P5S8sEj004LuwHTUbV88Bx8iNql2xlhyJSEL+j4fpZ35bOmTAdNw/ ft8FT6iql0xcZtJFOTnY5vcsb7pA6n82oGTLKhj6zALoHNdEpuVI4CdsJbunEm/uOPDR t2TKN9wzx3MFq/wgmHrRLZOV4JFKTdIgbVVvX11TwN7RXNxiHRrdW7fpo5NiVAmIZ0VK lWeXDkjXceTclI+2a+xgGX7FVrcr4KGtVzNhdnsHuxONqglystYUnOHb1vujEgcFmgt8 qtTZEfuIBUivAKsIESpf00X8+NKGJscLb12OioTVXmND8Vu0sI/67fy+6CsmQE4+4dey SZIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fMtJioHf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y2si5665947pgq.170.2019.04.04.02.46.07; Thu, 04 Apr 2019 02:46:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fMtJioHf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731156AbfDDI74 (ORCPT + 99 others); Thu, 4 Apr 2019 04:59:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:36306 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729877AbfDDI7v (ORCPT ); Thu, 4 Apr 2019 04:59:51 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E5BB12147C; Thu, 4 Apr 2019 08:59:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368390; bh=cOGDFI3eduanPU7WQB4Sc5tRC6VBg7S9g2FDSprIGZQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fMtJioHf70mjx0GoBf/+WLd08blR1XJbsLj45EMwTFnpZOCNix0p7mN1+B+qd9NZV vKA20wDUiccSLB1jH7kxydPe1CG1Iil8ImCDLVIzNYxUvXskpMh8RX5VPHNfc3uLDD FPSxsngZmpaowXIsi6/UgK/9pOfUp+eu+WXTloYs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 4.19 007/187] f2fs: fix to adapt small inline xattr space in __find_inline_xattr() Date: Thu, 4 Apr 2019 10:45:44 +0200 Message-Id: <20190404084603.436273149@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084603.119654039@linuxfoundation.org> References: <20190404084603.119654039@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 2c28aba8b2e2a51749fa66e01b68e1cd5b53e022 ] With below testcase, we will fail to find existed xattr entry: 1. mkfs.f2fs -O extra_attr -O flexible_inline_xattr /dev/zram0 2. mount -t f2fs -o inline_xattr_size=1 /dev/zram0 /mnt/f2fs/ 3. touch /mnt/f2fs/file 4. setfattr -n "user.name" -v 0 /mnt/f2fs/file 5. getfattr -n "user.name" /mnt/f2fs/file /mnt/f2fs/file: user.name: No such attribute The reason is for inode which has very small inline xattr size, __find_inline_xattr() will fail to traverse any entry due to first entry may not be loaded from xattr node yet, later, we may skip to check entire xattr datas in __find_xattr(), result in such wrong condition. This patch adds condition to check such case to avoid this issue. Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/xattr.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c index 087e53a2d96c..409a637f7a92 100644 --- a/fs/f2fs/xattr.c +++ b/fs/f2fs/xattr.c @@ -227,11 +227,11 @@ static struct f2fs_xattr_entry *__find_inline_xattr(struct inode *inode, { struct f2fs_xattr_entry *entry; unsigned int inline_size = inline_xattr_size(inode); + void *max_addr = base_addr + inline_size; list_for_each_xattr(entry, base_addr) { - if ((void *)entry + sizeof(__u32) > base_addr + inline_size || - (void *)XATTR_NEXT_ENTRY(entry) + sizeof(__u32) > - base_addr + inline_size) { + if ((void *)entry + sizeof(__u32) > max_addr || + (void *)XATTR_NEXT_ENTRY(entry) > max_addr) { *last_addr = entry; return NULL; } @@ -242,6 +242,13 @@ static struct f2fs_xattr_entry *__find_inline_xattr(struct inode *inode, if (!memcmp(entry->e_name, name, len)) break; } + + /* inline xattr header or entry across max inline xattr size */ + if (IS_XATTR_LAST_ENTRY(entry) && + (void *)entry + sizeof(__u32) > max_addr) { + *last_addr = entry; + return NULL; + } return entry; } -- 2.19.1