fscrypt-crypt-util: fix IV incrementing for --iv-ino-lblk-32
authorEric Biggers <ebiggers@google.com>
Thu, 1 Oct 2020 00:25:04 +0000 (17:25 -0700)
committerEryu Guan <guaneryu@gmail.com>
Sun, 11 Oct 2020 03:27:53 +0000 (11:27 +0800)
commit65cd8e8a8e815aab7285c794a3431247bfb1d2bd
treee9f046882ab90ea9a1a02bb11d69e25fba97642f
parentfa650493ef9f8f9aa4cdae0cc5c27f470293f2c0
fscrypt-crypt-util: fix IV incrementing for --iv-ino-lblk-32

fscrypt-crypt-util treats the "block number" part of the IV as 64-bit
when incrementing it.  That's wrong for --iv-ino-lblk-32 and
--iv-ino-lblk-64, as in those cases the block number should be 32-bit.

Fix this by using the correct length for the block number.

For --iv-ino-lblk-64 this doesn't actually matter, since in that case
the block number starts at 0 and never exceeds UINT32_MAX.

But for --iv-ino-lblk-32, the hashed inode number gets added to the
original block number to produce the IV block number, which can later
wrap around from UINT32_MAX to 0.  As a result, this change fixes
generic/602, though since the wraparound case isn't specifically tested
currently, the chance of failure was extremely small.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Daeho Jeong <daeho43@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
src/fscrypt-crypt-util.c