• David Howells's avatar
    assoc_array: Fix shortcut creation · 6d465fde
    David Howells authored
    BugLink: https://bugs.launchpad.net/bugs/1822271
    
    [ Upstream commit bb2ba2d7 ]
    
    Fix the creation of shortcuts for which the length of the index key value
    is an exact multiple of the machine word size.  The problem is that the
    code that blanks off the unused bits of the shortcut value malfunctions if
    the number of bits in the last word equals machine word size.  This is due
    to the "<<" operator being given a shift of zero in this case, and so the
    mask that should be all zeros is all ones instead.  This causes the
    subsequent masking operation to clear everything rather than clearing
    nothing.
    
    Ordinarily, the presence of the hash at the beginning of the tree index key
    makes the issue very hard to test for, but in this case, it was encountered
    due to a development mistake that caused the hash output to be either 0
    (keyring) or 1 (non-keyring) only.  This made it susceptible to the
    keyctl/unlink/valid test in the keyutils package.
    
    The fix is simply to skip the blanking if the shift would be 0.  For
    example, an index key that is 64 bits long would produce a 0 shift and thus
    a 'blank' of all 1s.  This would then be inverted and AND'd onto the
    index_key, incorrectly clearing the entire last word.
    
    Fixes: 3cb98950 ("Add a generic associative array implementation.")
    Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
    Signed-off-by: default avatarJames Morris <james.morris@microsoft.com>
    Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
    Signed-off-by: default avatarStefan Bader <stefan.bader@canonical.com>
    Acked-by: default avatarJuerg Haefliger <juerg.haefliger@canonical.com>
    Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
    6d465fde
assoc_array.c 52 KB