linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 3.18 01/10] assoc_array: Fix shortcut creation
@ 2019-03-13 19:18 Sasha Levin
  2019-03-13 19:18 ` [PATCH AUTOSEL 3.18 02/10] scsi: libiscsi: Fix race between iscsi_xmit_task and iscsi_complete_task Sasha Levin
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Sasha Levin @ 2019-03-13 19:18 UTC (permalink / raw)
  To: linux-kernel, stable; +Cc: David Howells, James Morris, Sasha Levin

From: David Howells <dhowells@redhat.com>

[ Upstream commit bb2ba2d75a2d673e76ddaf13a9bd30d6a8b1bb08 ]

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: 3cb989501c26 ("Add a generic associative array implementation.")
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <james.morris@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 lib/assoc_array.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/assoc_array.c b/lib/assoc_array.c
index 0d122543bd63..1db287fffb67 100644
--- a/lib/assoc_array.c
+++ b/lib/assoc_array.c
@@ -780,9 +780,11 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit,
 		new_s0->index_key[i] =
 			ops->get_key_chunk(index_key, i * ASSOC_ARRAY_KEY_CHUNK_SIZE);
 
-	blank = ULONG_MAX << (level & ASSOC_ARRAY_KEY_CHUNK_MASK);
-	pr_devel("blank off [%zu] %d: %lx\n", keylen - 1, level, blank);
-	new_s0->index_key[keylen - 1] &= ~blank;
+	if (level & ASSOC_ARRAY_KEY_CHUNK_MASK) {
+		blank = ULONG_MAX << (level & ASSOC_ARRAY_KEY_CHUNK_MASK);
+		pr_devel("blank off [%zu] %d: %lx\n", keylen - 1, level, blank);
+		new_s0->index_key[keylen - 1] &= ~blank;
+	}
 
 	/* This now reduces to a node splitting exercise for which we'll need
 	 * to regenerate the disparity table.
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-03-13 19:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-13 19:18 [PATCH AUTOSEL 3.18 01/10] assoc_array: Fix shortcut creation Sasha Levin
2019-03-13 19:18 ` [PATCH AUTOSEL 3.18 02/10] scsi: libiscsi: Fix race between iscsi_xmit_task and iscsi_complete_task Sasha Levin
2019-03-13 19:18 ` [PATCH AUTOSEL 3.18 03/10] scsi: libsas: Fix rphy phy_identifier for PHYs with end devices attached Sasha Levin
2019-03-13 19:18 ` [PATCH AUTOSEL 3.18 04/10] net: systemport: Fix reception of BPDUs Sasha Levin
2019-03-13 19:18 ` [PATCH AUTOSEL 3.18 05/10] net: mv643xx_eth: disable clk on error path in mv643xx_eth_shared_probe() Sasha Levin
2019-03-13 19:18 ` [PATCH AUTOSEL 3.18 06/10] arm64: Relax GIC version check during early boot Sasha Levin
2019-03-13 19:18 ` [PATCH AUTOSEL 3.18 07/10] net: marvell: mvneta: fix DMA debug warning Sasha Levin
2019-03-13 19:18 ` [PATCH AUTOSEL 3.18 08/10] tmpfs: fix link accounting when a tmpfile is linked in Sasha Levin
2019-03-13 19:18 ` [PATCH AUTOSEL 3.18 09/10] mdio_bus: Fix use-after-free on device_register fails Sasha Levin
2019-03-13 19:18 ` [PATCH AUTOSEL 3.18 10/10] net: set static variable an initial value in atl2_probe() Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).