Skip to content

Commit 555df33

Browse files
dhowellstorvalds
authored andcommitted
keys: Fix description size
The maximum key description size is 4095. Commit f771fde ("keys: Simplify key description management") inadvertantly reduced that to 255 and made sizes between 256 and 4095 work weirdly, and any size whereby size & 255 == 0 would cause an assertion in __key_link_begin() at the following line: BUG_ON(index_key->desc_len == 0); This can be fixed by simply increasing the size of desc_len in struct keyring_index_key to a u16. Note the argument length test in keyutils only checked empty descriptions and descriptions with a size around the limit (ie. 4095) and not for all the values in between, so it missed this. This has been addressed and https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/keyutils.git/commit/?id=066bf56807c26cd3045a25f355b34c1d8a20a5aa now exhaustively tests all possible lengths of type, description and payload and then some. The assertion failure looks something like: kernel BUG at security/keys/keyring.c:1245! ... RIP: 0010:__key_link_begin+0x88/0xa0 ... Call Trace: key_create_or_update+0x211/0x4b0 __x64_sys_add_key+0x101/0x200 do_syscall_64+0x5b/0x1e0 entry_SYSCALL_64_after_hwframe+0x44/0xa9 It can be triggered by: keyctl add user "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" a @s Fixes: f771fde ("keys: Simplify key description management") Reported-by: kernel test robot <[email protected]> Signed-off-by: David Howells <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent d1abaeb commit 555df33

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

include/linux/key.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ struct keyring_index_key {
9494
union {
9595
struct {
9696
#ifdef __LITTLE_ENDIAN /* Put desc_len at the LSB of x */
97-
u8 desc_len;
98-
char desc[sizeof(long) - 1]; /* First few chars of description */
97+
u16 desc_len;
98+
char desc[sizeof(long) - 2]; /* First few chars of description */
9999
#else
100-
char desc[sizeof(long) - 1]; /* First few chars of description */
101-
u8 desc_len;
100+
char desc[sizeof(long) - 2]; /* First few chars of description */
101+
u16 desc_len;
102102
#endif
103103
};
104104
unsigned long x;

0 commit comments

Comments
 (0)