Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3229903imc; Wed, 13 Mar 2019 12:11:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqy2ldCrEkL+QuOqxbgXRw9iApyZf1vauIQphIE1bG7JQbvBqS1OPOIprmTiq94zNf+b6OrT X-Received: by 2002:a17:902:bb86:: with SMTP id m6mr46843731pls.4.1552504304993; Wed, 13 Mar 2019 12:11:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552504304; cv=none; d=google.com; s=arc-20160816; b=qF6FZ/0HCJxcmHbU3b/0h85MLdbLzV+WxfblFCsCVHOviBYNWVou+3ApCW42OQzO7Z jX3x1/UTtye1SwbYz52Rtbs8ur6pflwuTzbFsdrxHt/NS8b4rEH+mm/RDt1RJQfwuiyF Ef6RIf+KaBjntXrx1W4QY3TxrXa/pcxCKBgdwpAriHeeRoQri8pVlk3KlUkypPFFAXrr G5JaVVbxXIFJU0qkvmFyK5ofbzP+qy7UAE2AcJgn0rhq/Wduw1w+GOdfL1q9rYL/W75P QMFYQr1EDQMvqC96kbtiZS0C1YoBoqEGjvmOYHsPx/6uPU/hyTE7uE8EMLSkc++Pc3pg f4iQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4Z/KOQ1KePFXQojAOb7rvE2zMzQ42v4KhF/XEsHBfkc=; b=IdZGON5aGBzPBF9WGUNlmh6sBBcZ3SgOxL1R2OURwfzSYqqoaHSH2kuC0pTCg9bEcc PMBp+0WIdfvxbKAFyrIaDFwGVK3oPvbw69mMMLZXR91luSwtO0K3+w5lthENsi4UcDME RtPo67jFx8NVGDnWxYS2VMXVXtFQi+ecsRrTVOY+/HlQXwyxZWYfoQQ2/i7frYQLkTwS L/SAY+CRIN+UmvqOj7pHJI+KealGxaT6wKwIulY/sx8PMG1QSyzNpbghlKURc3q0Qex8 /NP+CvQIYjOobZUe8qQN0TGYtSVFfT85E9k2rz0olsegoCebvfOPnaEpRohu4SaPyQqe +gNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nzIvynnS; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g9si9711338plm.157.2019.03.13.12.11.29; Wed, 13 Mar 2019 12:11:44 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=nzIvynnS; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727219AbfCMTKv (ORCPT + 99 others); Wed, 13 Mar 2019 15:10:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:41370 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727172AbfCMTKq (ORCPT ); Wed, 13 Mar 2019 15:10:46 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BAE332173C; Wed, 13 Mar 2019 19:10:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552504245; bh=Mitkl2Wh2KjmpejMZ0nyOJpDyQPyYKP0IOTNG1H5H9M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nzIvynnS0Cnysj4b10eBxYdi/Yy04vhSZF4whYmCczg5t4kzjY3cSn1O7RE+Kziyh N/fbpBM2X/gMsXU8s5MP346wtwbYuUHL0NQf+9OpB2MANxyIGGmizvO9efnK5ptvmt KWpXxRHiK7pfW8+GwlHL1EEPOMQ5rTTPXyM1B0yw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: David Howells , James Morris , Sasha Levin Subject: [PATCH AUTOSEL 4.20 12/60] assoc_array: Fix shortcut creation Date: Wed, 13 Mar 2019 15:09:33 -0400 Message-Id: <20190313191021.158171-12-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190313191021.158171-1-sashal@kernel.org> References: <20190313191021.158171-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Howells [ 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 Signed-off-by: James Morris Signed-off-by: Sasha Levin --- 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 @@ all_leaves_cluster_together: 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