Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5657516img; Wed, 27 Mar 2019 12:35:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqxTNvoXbVxAJ3usQfWyCP1it73z/BD+USKfgrkGWt+BJpRwBP36hCuzHLfnsO6Lh1XkZmDz X-Received: by 2002:a62:1701:: with SMTP id 1mr29349473pfx.120.1553715330710; Wed, 27 Mar 2019 12:35:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553715330; cv=none; d=google.com; s=arc-20160816; b=uC8F2DFzP9EqR/Y+dyjrNxI7v9HtV3tA4V4CLKwMF98uv845MSUS7FAVJs2HmRmdst zJ6Op4NM48vV8FdIJb8HOrM0MHRJVRaBE39fuqY8n5jpVGVLXCgb5M1YJMVuaxzRXBD7 VxVJkX7d5awagOsIvZ9AlAut9HOtCBSg2vQ73d8flT+hHxHIdWNit0NlcftuxWL7F3XK XCwdaiDErjEicXXdEnDpmJoO/TcXu8bPxSYfsCAa7BkwL+D4e3ZES443EZO1mCEWzChO 0J6cgyfq646I82X0gBNm4g81JOAnWCnZ05gnmOJgPyavMYOhfAOr0yA9Yn/3/05HFLxg OnhA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=shZW2K78wzk78s4G3pCHgz2+8avx1s26HL632reqCKs=; b=CWT97cEzid0pI5I2n81ARC0Glr6hSkJNFQOYycHvLRpVFDfDoup6YSepoJPIL+SGJz jXwegMp6hvhSAp8YYS7C0K/gtXFr0r/TFYv0FV2wtXNguvlpWy2yR7Rli9LqHl6KVbqH O6VRtUK7hOQ1SyiFRkJso3nnFjwUBlHucXI5FvARtdaZbYXLyj1Eyj0+ac8MMnHiyawR t1Q5zErYgbHCRSwLZ6LkV2v1NoPnd8Tx2ClKX5m+e2cmIQgH3L+5JvGQB1T4fS7LyFNM PxuhP/FZKUffkz0SLHz8mJIvxA3xumgHjmmEUGwmNiQpq0BolnEB1pJ6t1ivrE5lkiF7 NvJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tUCIrmnG; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z4si11691760plo.166.2019.03.27.12.35.15; Wed, 27 Mar 2019 12:35:30 -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=tUCIrmnG; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729074AbfC0SCG (ORCPT + 99 others); Wed, 27 Mar 2019 14:02:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:41832 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728954AbfC0SCF (ORCPT ); Wed, 27 Mar 2019 14:02:05 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B99162087C; Wed, 27 Mar 2019 18:02:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709724; bh=O4AMI9EhN+PA1BwNtalALrjToDvb4uQd16SFSnpAAEU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tUCIrmnGMltm+MoISd7IXgdmPvQSWcWtgfrLWK6tICpF92lcZDpyTzmqYM/5QWcI5 tnoRphC8L2q5+VDeFh+n9C7kbcok5VEutvju82s7JAfVZ8RNNskMWsKEdHyeFkGAB9 N8enNQ0luYx0bfcHyZziCdm4y2Ny6NiXDUgXuoxY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Chao Yu , Jaegeuk Kim , Sasha Levin , linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH AUTOSEL 5.0 005/262] f2fs: fix to adapt small inline xattr space in __find_inline_xattr() Date: Wed, 27 Mar 2019 13:57:40 -0400 Message-Id: <20190327180158.10245-5-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chao Yu [ 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 18d5ffbc5e8c..73b92985198b 100644 --- a/fs/f2fs/xattr.c +++ b/fs/f2fs/xattr.c @@ -224,11 +224,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; } @@ -239,6 +239,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