capability: introduce CAP_TO_MASK_CORRECTED() macro replacing CAP_TO_MASK()

linux/capability.h's CAP_TO_MASK potentially shifts a signed int "1"
(i.e. 32bit wide) left by 31 which means it becomes negative. That's
just weird, and ubsan complains about it. Let's introduce our own macro
CAP_TO_MASK_CORRECTED which doesn't fall into this trap, and make use of
it.

Fixes: #10347
This commit is contained in:
Lennart Poettering
2018-10-10 11:11:48 +02:00
parent ca92fe36e0
commit 5f00c5684f
2 changed files with 5 additions and 1 deletions
+4
View File
@@ -39,3 +39,7 @@ static inline bool cap_test_all(uint64_t caps) {
}
bool ambient_capabilities_supported(void);
/* Identical to linux/capability.h's CAP_TO_MASK(), but uses an unsigned 1U instead of a signed 1 for shifting left, in
* order to avoid complaints about shifting a signed int left by 31 bits, which would make it negative. */
#define CAP_TO_MASK_CORRECTED(x) (1U << ((x) & 31U))