From: Eric Biggers <ebiggers@kernel.org>
To: fstests@vger.kernel.org
Cc: linux-fscrypt@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net,
Jaegeuk Kim <jaegeuk@kernel.org>, Chao Yu <yuchao0@huawei.com>,
Daeho Jeong <daeho43@gmail.com>
Subject: [PATCH 1/5] fscrypt-crypt-util: clean up parsing --block-size and --inode-number
Date: Wed, 30 Sep 2020 17:25:03 -0700 [thread overview]
Message-ID: <20201001002508.328866-2-ebiggers@kernel.org> (raw)
In-Reply-To: <20201001002508.328866-1-ebiggers@kernel.org>
From: Eric Biggers <ebiggers@google.com>
For --block-size, check for strtoul() reporting an overflow.
For --inode-number, check for strtoull() reporting an overflow.
Also, move the check for 32-bit inode numbers into a more logical place
(the place where we check the encryption format-specific limitations).
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
src/fscrypt-crypt-util.c | 25 ++++++++++---------------
1 file changed, 10 insertions(+), 15 deletions(-)
diff --git a/src/fscrypt-crypt-util.c b/src/fscrypt-crypt-util.c
index ce9da85d..d9189346 100644
--- a/src/fscrypt-crypt-util.c
+++ b/src/fscrypt-crypt-util.c
@@ -26,6 +26,7 @@
#include <linux/types.h>
#include <stdarg.h>
#include <stdbool.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -1756,18 +1757,6 @@ static u8 parse_mode_number(const char *arg)
return num;
}
-static u32 parse_inode_number(const char *arg)
-{
- char *tmp;
- unsigned long long num = strtoull(arg, &tmp, 10);
-
- if (num <= 0 || *tmp)
- die("Invalid inode number: %s", arg);
- if ((u32)num != num)
- die("Inode number %s is too large; must be 32-bit", arg);
- return num;
-}
-
struct key_and_iv_params {
u8 master_key[MAX_KEY_SIZE];
int master_key_size;
@@ -1777,7 +1766,7 @@ struct key_and_iv_params {
bool file_nonce_specified;
bool iv_ino_lblk_64;
bool iv_ino_lblk_32;
- u32 inode_number;
+ u64 inode_number;
u8 fs_uuid[UUID_SIZE];
bool fs_uuid_specified;
};
@@ -1842,6 +1831,8 @@ static void get_key_and_iv(const struct key_and_iv_params *params,
die("%s requires --inode-number", opt);
if (params->mode_num == 0)
die("%s requires --mode-num", opt);
+ if (params->inode_number > UINT32_MAX)
+ die("%s can't use --inode-number > UINT32_MAX", opt);
}
switch (params->kdf) {
@@ -1957,8 +1948,9 @@ int main(int argc, char *argv[])
while ((c = getopt_long(argc, argv, "", longopts, NULL)) != -1) {
switch (c) {
case OPT_BLOCK_SIZE:
+ errno = 0;
block_size = strtoul(optarg, &tmp, 10);
- if (block_size <= 0 || *tmp)
+ if (block_size <= 0 || *tmp || errno)
die("Invalid block size: %s", optarg);
break;
case OPT_DECRYPT:
@@ -1980,7 +1972,10 @@ int main(int argc, char *argv[])
usage(stdout);
return 0;
case OPT_INODE_NUMBER:
- params.inode_number = parse_inode_number(optarg);
+ errno = 0;
+ params.inode_number = strtoull(optarg, &tmp, 10);
+ if (params.inode_number <= 0 || *tmp || errno)
+ die("Invalid inode number: %s", optarg);
break;
case OPT_IV_INO_LBLK_32:
params.iv_ino_lblk_32 = true;
--
2.28.0
next prev parent reply other threads:[~2020-10-01 0:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-01 0:25 [PATCH 0/5] xfstests: test f2fs compression+encryption Eric Biggers
2020-10-01 0:25 ` Eric Biggers [this message]
2020-10-01 0:25 ` [PATCH 2/5] fscrypt-crypt-util: fix IV incrementing for --iv-ino-lblk-32 Eric Biggers
2020-10-01 0:25 ` [PATCH 3/5] fscrypt-crypt-util: add --block-number option Eric Biggers
2020-10-01 0:25 ` [PATCH 4/5] common/f2fs: add _require_scratch_f2fs_compression() Eric Biggers
2020-10-01 0:25 ` [PATCH 5/5] f2fs: verify ciphertext of compressed+encrypted file Eric Biggers
2020-10-07 3:48 ` [PATCH 0/5] xfstests: test f2fs compression+encryption Eric Biggers
2020-10-07 4:27 ` [f2fs-dev] " Daeho Jeong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201001002508.328866-2-ebiggers@kernel.org \
--to=ebiggers@kernel.org \
--cc=daeho43@gmail.com \
--cc=fstests@vger.kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fscrypt@vger.kernel.org \
--cc=yuchao0@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox