lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 18 Dec 2018 11:35:39 -0500
From:   "Theodore Y. Ts'o" <tytso@....edu>
To:     Andreas Dilger <adilger@...ger.ca>
Cc:     Ext4 Developers List <linux-ext4@...r.kernel.org>
Subject: Re: [PATCH] ext4: avoid declaring fs inconsistent due to invalid
 file handles

On Mon, Dec 17, 2018 at 10:43:40PM -0700, Andreas Dilger wrote:
> I don't think that it is verboten to use binary flag values in an enum,
> if you explicitly specify the values, which is why I used "0x01", "0x02"
> to make it more clear these are binary values.  IMHO, using a named enum
> is a good way to annotate the function parameters rather than a generic
> "int flag" parameter that is ambiguous unless you look at the function
> code to see what the values of "flag" might be.

I tend to only use enums in this kind of way:

enum classification_levels { 
	FOR_OFFICIAL_USE_ONLY, 
	CONFIDENTIAL,
	SECRET, 
	TOP_SECRET, 
};

I think the reason why I've never used it for type checking is because
for gcc and sparse, it doesn't work.  For the below example, "gcc
-Wall foo.c" won't complain at all.  Sparse complains only about the
"return a | b;" line, because we're combining two different enum
types.  Sparse doesn't say boo that I passed EXT4_IGET_NORMAL where a
classification_levels, and secret where an ext4_iget_flags is
expected:

enum ext4_iget_flags {
	EXT4_IGET_RESERVED = 0x00,    /* just guessing, see further below */
	EXT4_IGET_NORMAL   = 0x01,
	EXT4_IGET_HANDLE   = 0x02
};

int combine(enum classification_levels a, enum ext4_iget_flags b)
{
	return a | b;
}


int main(int argc, char **argv)
{
	printf("%d\n", combine(EXT4_IGET_NORMAL, secret));
	exit(1);
}
	
Then again, llvm does correctly complain, and at least for Android
configs, llvm will complain kernels correctly (although I'm not sure
enterprise distros trust LLVM just yet), and I do agree that it's
useful from a documentation perspective.

Cheers,

					- Ted

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ