Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1303675lqh; Mon, 6 May 2024 03:49:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXu6Y+ctx6970CJAKd8sDghqqbj5RruPrd3bfBVd09Jm9NTHUKlFFd051rqT6RsaofA+7Ac7ZneGIb47PHFiLYWvrAtS99VL0rCTc+vRg== X-Google-Smtp-Source: AGHT+IGGl6eguKzLNDSPHeV5RrsJHMP2+W1+DPZ1lyYuJxkgga6cB+j38sAKVBLuv/5EIQ1Pi5vz X-Received: by 2002:a17:90b:151:b0:2af:de3:f0e3 with SMTP id em17-20020a17090b015100b002af0de3f0e3mr12668300pjb.23.1714992565784; Mon, 06 May 2024 03:49:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714992565; cv=pass; d=google.com; s=arc-20160816; b=lGAaAaIfgwmp9LW3jcmVaxnvM6BjYGJCmVHZug7SCifxvT29/HojWyJITOVvPqHgiG qm/kOywIYldYu+6Jm/g8Q25jvaDqlI9B4Wl79o0F5Jk2Yz1Fnvb19MxD5PJJydhVvO7m PHuvxHMGTCt815zJPrWwxP0nCAOb6Hn06q/SGlexC4boRb/eCatWPRwJLlCu7VLoxIP8 YFRzQ5562S+omnAyPD2sygdu6WW4DKH0pv4Y6qkB7wtx9QBPSLxRdZtgrQ2hNUgSLC8R X7p2iUSUUKMN/Tq+Tzp7gBaCcqwWuBbBFViKiFhokrvWIZAFWSIi5FWddq0DZrFHfqv7 7PrQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=V7TsJpeaZSd1kAAkTHGzZC+p11S6ODvpkdtqbNLkuXM=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=Cd/x01lhhtV1836dKF2MXAcRgePymdE7xXoiYcYokaTA173HXDx3f1wsajoGHyDEsx pGt28hHx+CS8nVnnuyBvmt6K7+FNoVrMssq+/PPzQkvT/qUOjdGu8Yz+kwfkf4MlchRA HbTQYBo9wW7ws2POVlBf7ABmvCG7Qu8ESJTTDULoTpldZyHvYyNeDO34WNNmSUVHq9EP ysdNyCrJ9NMLZtjCB/am9M9grGsWAGD0qsIfssnYGwzUlHqNpbxRomdm2cry5yvVKNKS w03Ftu0jLcH4qFQ5UlrJu+pf0lhpfjIcPwt45+LqTIf0LdepHidlyLuty3r3OgzXpTaE 7f6Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OBGl3ScG; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-169699-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169699-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id gd10-20020a17090b0fca00b002ad4890f36asi8400164pjb.173.2024.05.06.03.49.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 03:49:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169699-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OBGl3ScG; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-169699-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169699-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id BBB3EB234C3 for ; Mon, 6 May 2024 10:47:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 44DD9142E6B; Mon, 6 May 2024 10:46:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OBGl3ScG" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BD11142913 for ; Mon, 6 May 2024 10:46:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714992415; cv=none; b=l612AEWIv9NXuAPA/jOY8Y5c+08L1FC0cCDmW4ohuFWRS1duwPP7N+C0q4xHBKme86Hggw2gfC+k18qzC9ax5sOyV99Cm7byHi1dRWjtZMVK1MYtODiJIrvzmHCFUCgKyWeO5xx8IpNWK/tYk7hJDpo1av5/oeMbAvhMpCSfQxo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714992415; c=relaxed/simple; bh=OZhJqt+o8seKhbAIpLU14VakbFXx8o5jipF26rcAztU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=QP1zS/lPFHO77prgrOn34bPqic7b6CM8wIdY0je14jwguNn8WNlUme+OwsaVwlJ/H0O+4TaLOU/cVjB8F41xAUoMDnQIADVCJgI/mhm8cC5qUw6uNPwcn9nEmmV51E+23JWCK3JZiS0IPuny15Si/5TzIy7wDq8ecgUlyuGlAE8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OBGl3ScG; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00129C116B1; Mon, 6 May 2024 10:46:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714992415; bh=OZhJqt+o8seKhbAIpLU14VakbFXx8o5jipF26rcAztU=; h=From:To:Cc:Subject:Date:From; b=OBGl3ScGEUxgguSlQ75+eY+VpwBMeAwETZy3PrphT3PgVQx0OzEbAdBCjVG4Niou5 N7ro6gE4pvNbuX5T5AhOu5+EeEQ/gsZJuX6xQ+bwu47WvIjiohH49UFFk9KCq1M531 aYak/5xVkvJvObeiZxaiBt3NF83mQADn0Qq4qytxk1pwXEmCEjyoQrz/4BfAy4STr6 0oT3Fg2MnCjbbFqTth/qgMu94AYycZ07wlWLT+BHm+yTC9/eMJMj6gKHKSLRvBAn0x Yd8LYEgaBjzYSyX5AIOwhFP/XOTYGUnE/hSVV1JnzdyFu/QaUlhrUtFt/efBD1T1ja jLE5NNHq6ouUQ== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH] f2fs: check validation of fault attrs in f2fs_build_fault_attr() Date: Mon, 6 May 2024 18:46:50 +0800 Message-Id: <20240506104650.778504-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit - It missed to check validation of fault attrs in parse_options(), let's fix to add check condition in f2fs_build_fault_attr(). - Use f2fs_build_fault_attr() in __sbi_store() to clean up code. Signed-off-by: Chao Yu --- fs/f2fs/f2fs.h | 12 ++++++++---- fs/f2fs/super.c | 27 ++++++++++++++++++++------- fs/f2fs/sysfs.c | 14 ++++++++++---- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 95a40d4f778f..b03d75e4eedc 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -72,7 +72,7 @@ enum { struct f2fs_fault_info { atomic_t inject_ops; - unsigned int inject_rate; + int inject_rate; unsigned int inject_type; }; @@ -4597,10 +4597,14 @@ static inline bool f2fs_need_verity(const struct inode *inode, pgoff_t idx) } #ifdef CONFIG_F2FS_FAULT_INJECTION -extern void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate, - unsigned int type); +extern int f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned long rate, + unsigned long type); #else -#define f2fs_build_fault_attr(sbi, rate, type) do { } while (0) +int f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned long rate, + unsigned long type) +{ + return 0; +} #endif static inline bool is_journalled_quota(struct f2fs_sb_info *sbi) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index a4bc26dfdb1a..94918ae7eddb 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -66,21 +66,31 @@ const char *f2fs_fault_name[FAULT_MAX] = { [FAULT_NO_SEGMENT] = "no free segment", }; -void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate, - unsigned int type) +int f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned long rate, + unsigned long type) { struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info; if (rate) { + if (rate > INT_MAX) + return -EINVAL; atomic_set(&ffi->inject_ops, 0); - ffi->inject_rate = rate; + ffi->inject_rate = (int)rate; } - if (type) - ffi->inject_type = type; + if (type) { + if (type >= BIT(FAULT_MAX)) + return -EINVAL; + ffi->inject_type = (unsigned int)type; + } if (!rate && !type) memset(ffi, 0, sizeof(struct f2fs_fault_info)); + else + f2fs_info(sbi, + "build fault injection attr: rate: %lu, type: 0x%lx", + rate, type); + return 0; } #endif @@ -886,14 +896,17 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount) case Opt_fault_injection: if (args->from && match_int(args, &arg)) return -EINVAL; - f2fs_build_fault_attr(sbi, arg, F2FS_ALL_FAULT_TYPE); + if (f2fs_build_fault_attr(sbi, arg, + F2FS_ALL_FAULT_TYPE)) + return -EINVAL; set_opt(sbi, FAULT_INJECTION); break; case Opt_fault_type: if (args->from && match_int(args, &arg)) return -EINVAL; - f2fs_build_fault_attr(sbi, 0, arg); + if (f2fs_build_fault_attr(sbi, 0, arg)) + return -EINVAL; set_opt(sbi, FAULT_INJECTION); break; #else diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index a568ce96cf56..7aa3844e7a80 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -484,10 +484,16 @@ static ssize_t __sbi_store(struct f2fs_attr *a, if (ret < 0) return ret; #ifdef CONFIG_F2FS_FAULT_INJECTION - if (a->struct_type == FAULT_INFO_TYPE && t >= BIT(FAULT_MAX)) - return -EINVAL; - if (a->struct_type == FAULT_INFO_RATE && t >= UINT_MAX) - return -EINVAL; + if (a->struct_type == FAULT_INFO_TYPE) { + if (f2fs_build_fault_attr(sbi, 0, t)) + return -EINVAL; + return count; + } + if (a->struct_type == FAULT_INFO_RATE) { + if (f2fs_build_fault_attr(sbi, t, 0)) + return -EINVAL; + return count; + } #endif if (a->struct_type == RESERVED_BLOCKS) { spin_lock(&sbi->stat_lock); -- 2.40.1