Re: [PATCH 053/190] Revert "ecryptfs: replace BUG_ON with error handling code"
From: Al Viro
Date: Wed Apr 21 2021 - 13:03:44 EST
On Wed, Apr 21, 2021 at 11:13:29AM -0500, Tyler Hicks wrote:
> > It *is* functionally harmless, AFAICS, but only because the condition
> > is really impossible. However,
> > * it refers to vague (s)tool they'd produced, nevermind that
> > all they really do is "find BUG_ON(), replace with returning an error".
> > * unlike BUG_ON(), the replacement does *NOT* document the
> > fact that condition should be impossible.
> > IMO either should be sufficient for rejecting the patch.
>
> I agree that it was not a malicious change. There are other places
> within the same function that return -EINVAL and the expectation is that
> errors from this function should be handled safely.
Umm... Assuming that failure exits in the callers will function properly
if those conditions are true. Which is not obvious at all.
> That said, I can find no real-world reports of this BUG_ON() ever being
> a problem and I don't think that there's any actual need for this
> change. So, I'm alright with it being reverted considering the
> circumstances.
AFAICS, at least some parts of that BUG_ON() are provably impossible
(e.g. NULL crypt_stat would've oopsed well upstream of the only call
of that function). ECRYPTFS_STRUCT_INITIALIZED is set after
ecryptfs_alloc_inode() and never cleared, i.e. it should be present
in ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat.flags for
all inodes. And crypt_stat we are passing to that thing is
calculated as &(ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat),
which is another reason why it can't be NULL.
Incidentally, what's ecryptfs_setattr() doing with similar check?
It had been introduced in e10f281bca03 "eCryptfs: initialize crypt_stat
in setattr", which claims
Recent changes in eCryptfs have made it possible to get to ecryptfs_setattr()
with an uninitialized crypt_stat struct. This results in a wide and colorful
variety of unpleasantries. This patch properly initializes the crypt_stat
structure in ecryptfs_setattr() when it is necessary to do so.
and AFAICS at that point the call of ecryptfs_init_crypt_stat() in
ecryptfs_alloc_inode() had already been there and EXCRYPTFS_STRUCT_INITIALIZED
had been (unconditionally) set by it. So how could that check trigger in
ecryptfs_setattr()? No direct calls of that function (then as well as now),
it's only reachable as ecryptfs_{symlink,dir,main}_iops.setattr. The first
two could only end up set by ecryptfs_interpose(), for inode returned by
iget5_locked() (i.e. one that had been returned by ->alloc_inode()),
the last is set by ecryptfs_init_inode(), called by ecryptfs_inode_set(),
passed as callback to iget5_locked() by the same ecryptfs_interpose().
IOW, again, the inode must have been returned by ->alloc_inode().
I realize that it had been a long time ago, but... could somebody
recall what that patch had been about? Michael?
Commit in question contains another (and much bigger) chunk; do
the comments in commit message refer to it? Because it really
looks like
if (!(crypt_stat->flags & ECRYPTFS_STRUCT_INITIALIZED))
ecryptfs_init_crypt_stat(crypt_stat);
part in ecryptfs_setattr() is a confusing no-op...