Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp126362imj; Thu, 14 Feb 2019 16:53:10 -0800 (PST) X-Google-Smtp-Source: AHgI3IbbXJD7vf1Dny4NJPm79zvRTb2MOskF+TFLFvy7jCKj29pvnWGKHYPB2yEYj1S4zWVxJS9Z X-Received: by 2002:a63:ae0e:: with SMTP id q14mr6658188pgf.151.1550191990919; Thu, 14 Feb 2019 16:53:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550191990; cv=none; d=google.com; s=arc-20160816; b=YXop+XFk1PhHMTogQDjETbxYLVgSAoMqVawy7Q5Pmr53/mdxeGXXCYH4XQaj7rtixH nVkWBnFr1JSYokIhvMLatY58p4YbNXSBvq5VTTDYSEGDoCqQc2s+i+laINef3JpvWIAj pw8/pgxwzt9D9pUgnyW/M+7QTVb0rfzhRrnShXQ/KNcX37YPFBIVD/yAPJ7ja/VqOZoM RSvBHBbYksQCUP7Ncr8Wumv1CXIwKe8WuVBG7wGhGctg9QaDDflRmZGi1EDnPkePbTPg MB/iYBs+XKOcQeNPyM+gwbQIOToJNDRFFrUZwUY+BQ/HDXpp5JIESrFQE5GQf6EFEF56 0+0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization; bh=1YAfATMldukHqE4OsRFSmoCO4eZ3kVm2BkGWpHHm968=; b=i9bMdVBApYHgIp8xfR3rVHzfkgn4YP5p6onT60iAETQ9nSozBpmvGtP8RU3YjQ6CSM 2R9LRPkdx35jJIQP1XFhcvzyC6q5PE5AbsnuAGOa4ybKD7AhRaw11IU2NC4aR1oZWfHr JplkSGuMh3QydHirIqOk0Foou8ptWZZqacz0daSs4gV8Vc2VyDpu18B1c4FUnk+9PuVt 6jsO7ktHoOJvEHd/wQ8zh2ZX/bHIgJHQAMOWP7s+npXyk7cjdon4RWY8jNq7oI73/qzC 96vxWV3EUtYYdlm1t5CbvliQ0vRxttqJQQJYA3FrzamVqDXiKB2+z9HtyVRGivKLuYHo fhTg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t4si3931555pga.83.2019.02.14.16.52.55; Thu, 14 Feb 2019 16:53:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2395434AbfBNQUS (ORCPT + 99 others); Thu, 14 Feb 2019 11:20:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42398 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728037AbfBNQUR (ORCPT ); Thu, 14 Feb 2019 11:20:17 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CE3A8E6A9F; Thu, 14 Feb 2019 16:20:17 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-121-129.rdu2.redhat.com [10.10.121.129]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1C785C23D; Thu, 14 Feb 2019 16:20:16 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 2/4] assoc_array: Fix shortcut creation From: David Howells To: jmorris@namei.org Cc: linux-security-module@vger.kernel.org, keyrings@vger.kernel.org, dhowells@redhat.com, ebiggers@kernel.org, linux-kernel@vger.kernel.org Date: Thu, 14 Feb 2019 16:20:15 +0000 Message-ID: <155016121107.8115.8131805004120069255.stgit@warthog.procyon.org.uk> In-Reply-To: <155016118572.8115.3243711127043478822.stgit@warthog.procyon.org.uk> References: <155016118572.8115.3243711127043478822.stgit@warthog.procyon.org.uk> User-Agent: StGit/unknown-version MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 14 Feb 2019 16:20:17 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 c6659cb37033..59875eb278ea 100644 --- a/lib/assoc_array.c +++ b/lib/assoc_array.c @@ -768,9 +768,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.