Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5655424img; Wed, 27 Mar 2019 12:33:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqzt+aAdHgh+LI7xTLkgqKk4Enjhn5O2+vhc8YAmQz2p4ukCsOn9E3jEJxvB8dUvtlxIwSi/ X-Received: by 2002:a17:902:87:: with SMTP id a7mr38309124pla.295.1553715182046; Wed, 27 Mar 2019 12:33:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553715182; cv=none; d=google.com; s=arc-20160816; b=MjVXIUQx73cOlRTGK+fPJy/dH+yXw/n/uhfFuVw9aoqe24Cf6mjbc+Uft3FpDp0U8f pRztOO4se8NSSEH7mLOmZbgddBpR/Z0XryIXVeMJ7Lhl+QAb+Gy1Lf873paxv/XcaKVf IVAt+8N2sttneYc8+YrkDEYVpLbLNioeiS/fwtY5fKTtc3Ds2AdXaQqJzWsw0K0PhWPE BjZb735r4dw11p0eMs/R1WxZmSk2Ql6MewApRzDgReMUzAsrp4ASsisDlzljRRUvjZzn zYGOTvUCLqpzvxR0Wqm6TxNSvrRyctSc8eQHv83ABuaSUdLi+xOfOnuzhWF3v6G4V4SB LL6A== 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=CU2OKLHTrQDPSILhhs/84NWQNaWtAigkHnamdaLBQnQ=; b=ZK8LyyR7vn9qVOBtuM7kaMH7zv97XVVPn6O/J9YeXsDrQO8ypoiM5uV1MPOIQFtO9r srQQ9Nknvfgt44SDjncktQmmVL3fwUs68BFi+52VQB3ROErP9XrQ/m6qxEFcV3Up2czr UuVclCdIJNX3dhoZ3z6gwvz9w+Bdyghe2IStVmJg70XP0WWN0KLV4yT53y3C7MBNiTb4 i395u7+5YwM1MmsmBjlkXAUSWDXcsa+kQFG113TYBWCmy/trrjzj08rFiJBPR3AZ5N7U QxQyD28hPGYifcDo5mtMl0jDf3mf+GNtQKC00CHz6aR384D0S9ZjlGVwktCUnxl2jMg2 K7pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KXD+bMKJ; 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 f32si20962966plf.24.2019.03.27.12.32.46; Wed, 27 Mar 2019 12:33:02 -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=KXD+bMKJ; 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 S2387804AbfC0Tat (ORCPT + 99 others); Wed, 27 Mar 2019 15:30:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:43706 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732295AbfC0SD1 (ORCPT ); Wed, 27 Mar 2019 14:03:27 -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 D6049217F5; Wed, 27 Mar 2019 18:03:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709806; bh=O8aNYSONCd7VlaHdRHMo1PFDHvchIpv3cLyN2/yf5Ic=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KXD+bMKJlvDkXzZZ5PETwzE7+XmQMUwi03W9U78UTp3bR9miMW46isln5oiEhQg6i cqkoNJ/zbHik1lm1GC7WVriVM44VOADNaH6HkJq9ywjfZpMgz6oUFIkmPakVC016H+ DQICkSLHzICibnRYnCjnNcnRoqsJ/oeA+taO75QA= 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 048/262] f2fs: fix to check inline_xattr_size boundary correctly Date: Wed, 27 Mar 2019 13:58:23 -0400 Message-Id: <20190327180158.10245-48-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 500e0b28ecd3c5aade98f3c3a339d18dcb166bb6 ] We use below condition to check inline_xattr_size boundary: if (!F2FS_OPTION(sbi).inline_xattr_size || F2FS_OPTION(sbi).inline_xattr_size >= DEF_ADDRS_PER_INODE - F2FS_TOTAL_EXTRA_ATTR_SIZE - DEF_INLINE_RESERVED_SIZE - DEF_MIN_INLINE_SIZE) There is there problems in that check: - we should allow inline_xattr_size equaling to min size of inline {data,dentry} area. - F2FS_TOTAL_EXTRA_ATTR_SIZE and inline_xattr_size are based on different size unit, previous one is 4 bytes, latter one is 1 bytes. - DEF_MIN_INLINE_SIZE only indicate min size of inline data area, however, we need to consider min size of inline dentry area as well, minimal inline dentry should at least contain two entries: '.' and '..', so that min inline_dentry size is 40 bytes. .bitmap 1 * 1 = 1 .reserved 1 * 1 = 1 .dentry 11 * 2 = 22 .filename 8 * 2 = 16 total 40 Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/f2fs.h | 1 - fs/f2fs/super.c | 13 +++++++------ include/linux/f2fs_fs.h | 13 +++++++------ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 12fabd6735dd..279bc00489cc 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -456,7 +456,6 @@ struct f2fs_flush_device { /* for inline stuff */ #define DEF_INLINE_RESERVED_SIZE 1 -#define DEF_MIN_INLINE_SIZE 1 static inline int get_extra_isize(struct inode *inode); static inline int get_inline_xattr_addrs(struct inode *inode); #define MAX_INLINE_DATA(inode) (sizeof(__le32) * \ diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 93d7427d8883..5892fa3c885f 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -834,12 +834,13 @@ static int parse_options(struct super_block *sb, char *options) "set with inline_xattr option"); return -EINVAL; } - if (!F2FS_OPTION(sbi).inline_xattr_size || - F2FS_OPTION(sbi).inline_xattr_size >= - DEF_ADDRS_PER_INODE - - F2FS_TOTAL_EXTRA_ATTR_SIZE - - DEF_INLINE_RESERVED_SIZE - - DEF_MIN_INLINE_SIZE) { + if (F2FS_OPTION(sbi).inline_xattr_size < + sizeof(struct f2fs_xattr_header) / sizeof(__le32) || + F2FS_OPTION(sbi).inline_xattr_size > + DEF_ADDRS_PER_INODE - + F2FS_TOTAL_EXTRA_ATTR_SIZE / sizeof(__le32) - + DEF_INLINE_RESERVED_SIZE - + MIN_INLINE_DENTRY_SIZE / sizeof(__le32)) { f2fs_msg(sb, KERN_ERR, "inline xattr size is out of range"); return -EINVAL; diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index d7711048ef93..c524ad7d31da 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -489,12 +489,12 @@ typedef __le32 f2fs_hash_t; /* * space utilization of regular dentry and inline dentry (w/o extra reservation) - * regular dentry inline dentry - * bitmap 1 * 27 = 27 1 * 23 = 23 - * reserved 1 * 3 = 3 1 * 7 = 7 - * dentry 11 * 214 = 2354 11 * 182 = 2002 - * filename 8 * 214 = 1712 8 * 182 = 1456 - * total 4096 3488 + * regular dentry inline dentry (def) inline dentry (min) + * bitmap 1 * 27 = 27 1 * 23 = 23 1 * 1 = 1 + * reserved 1 * 3 = 3 1 * 7 = 7 1 * 1 = 1 + * dentry 11 * 214 = 2354 11 * 182 = 2002 11 * 2 = 22 + * filename 8 * 214 = 1712 8 * 182 = 1456 8 * 2 = 16 + * total 4096 3488 40 * * Note: there are more reserved space in inline dentry than in regular * dentry, when converting inline dentry we should handle this carefully. @@ -506,6 +506,7 @@ typedef __le32 f2fs_hash_t; #define SIZE_OF_RESERVED (PAGE_SIZE - ((SIZE_OF_DIR_ENTRY + \ F2FS_SLOT_LEN) * \ NR_DENTRY_IN_BLOCK + SIZE_OF_DENTRY_BITMAP)) +#define MIN_INLINE_DENTRY_SIZE 40 /* just include '.' and '..' entries */ /* One directory entry slot representing F2FS_SLOT_LEN-sized file name */ struct f2fs_dir_entry { -- 2.19.1