[CRIU] [PATCH 2/2] compel/ksigset: fix ksigaddset() UB and flushing mask

Dmitry Safonov dsafonov at virtuozzo.com
Tue Mar 7 11:37:17 PST 2017


Found by Coverity error:
> CID 172193 (#1 of 1): Bad bit shift operation (BAD_SHIFT)
> 1. large_shift: In expression 1 << sig % 64, left shifting
> by more than 31 bits has undefined behavior. The shift amount,
> sig % 64, is as much as 63.

That is:
1. yes, UB
2. while adding a signal to mask, this has flushed all other
   signals from mask.

Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
 compel/include/uapi/ksigset.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compel/include/uapi/ksigset.h b/compel/include/uapi/ksigset.h
index ed6950a33cb8..f6b124bf3431 100644
--- a/compel/include/uapi/ksigset.h
+++ b/compel/include/uapi/ksigset.h
@@ -20,6 +20,6 @@ static inline void ksigemptyset(k_rtsigset_t *set)
 static inline void ksigaddset(k_rtsigset_t *set, int _sig)
 {
 	int sig = _sig - 1;
-	set->sig[sig / _NSIG_BPW] = 1 << (sig % _NSIG_BPW);
+	set->sig[sig / _NSIG_BPW] |= 1UL << (sig % _NSIG_BPW);
 }
 #endif
-- 
2.11.1



More information about the CRIU mailing list