Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1551616ybz; Thu, 30 Apr 2020 01:08:51 -0700 (PDT) X-Google-Smtp-Source: APiQypKCOPfBDycxspAbh5OpjBUdlNN5wH+TGQAe4jalHugzo83iG+sjMJnTVF64l4FqCYnbOtA+ X-Received: by 2002:a17:906:cec5:: with SMTP id si5mr1591599ejb.267.1588234131247; Thu, 30 Apr 2020 01:08:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588234131; cv=none; d=google.com; s=arc-20160816; b=yNG9yJBSlqvL3sHodO3q5cH8G75aoJshG5vT+Nnyh8xQUKCOIicUhx3Fq+g5CjuKZ3 5zXAev9IROzu3jpb9ODGfXcfWr/Pz9CpzwxclYEQDr6RYKra7MpQFy303e+oMWBjL/Te o662u+IPUKz6m6/NTnp7Z+4RrTmZlxhL72nAaTQhRthKOAVDIdeVxY5bqg5eyaPIsUsd rOjdABVQ737CWq0ypvUlLOERwU6FAE343dRPBEyGF5hvBQgQLogtvtrhVfXqUpTLPLPF GA2gDpRN7Fo9frWLBsW2Xsy5STjdSd6tHAP709WP285IYYbOtuLPKT6i8JiJKIzecryY /g0w== 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 :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=hcdc4iQt+PLC37V4eAHhxl59DsTINjV4qugxATCJ+/w=; b=OOoImYnn+hwgcJmA8QUwWp4CneIRqoep4BpEabKJzHs3STQ1njYjdVjKI4XCLARkFb C+E9WVEdan7hfnFG8kooH/UIAF4Z372HD+oDeCgO52O3T2ZD2wQsTJFFS0npiM2S17op dxmiN4WBZWn8e5CB4Kymlprjip/rt+jJpzXykOLsIOOIZ70iRNou2KgubYkT8M+kwwfJ gVkgNbFWMZYMGjn41+An24leCict/e96QlczVvj/DsABHuMHbFMJlMx6eovub51mVZhZ QVtGwnSayMvj602I78NXRxuF0/o+23HYaKiPK4iVR41bCIRGvEmLpXLI44yxkboREgB7 X1kw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e16si4832253eds.503.2020.04.30.01.08.26; Thu, 30 Apr 2020 01:08:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726565AbgD3IDx convert rfc822-to-8bit (ORCPT + 99 others); Thu, 30 Apr 2020 04:03:53 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([207.82.80.151]:41484 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726476AbgD3IDw (ORCPT ); Thu, 30 Apr 2020 04:03:52 -0400 Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-188-QwramPYPODaeNg-qytVVbw-1; Thu, 30 Apr 2020 09:03:47 +0100 X-MC-Unique: QwramPYPODaeNg-qytVVbw-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Thu, 30 Apr 2020 09:03:47 +0100 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Thu, 30 Apr 2020 09:03:47 +0100 From: David Laight To: 'Roberto Sassu' , "zohar@linux.ibm.com" , "rgoldwyn@suse.de" CC: "linux-integrity@vger.kernel.org" , "linux-security-module@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "silviu.vlasceanu@huawei.com" , "krzysztof.struczynski@huawei.com" , "stable@vger.kernel.org" Subject: RE: [RESEND][PATCH v2 3/6] ima: Fix ima digest hash table key calculation Thread-Topic: [RESEND][PATCH v2 3/6] ima: Fix ima digest hash table key calculation Thread-Index: AQHWHS80o0OMQYVPmUqc5kiRSsIx16iRUJzg Date: Thu, 30 Apr 2020 08:03:47 +0000 Message-ID: <060c71f88c8d4c6a9fafca4b329605c5@AcuMS.aculab.com> References: <20200427102900.18887-3-roberto.sassu@huawei.com> <20200428073010.25631-1-roberto.sassu@huawei.com> In-Reply-To: <20200428073010.25631-1-roberto.sassu@huawei.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Roberto Sassu > Sent: 28 April 2020 08:30 > From: Krzysztof Struczynski > > Function hash_long() accepts unsigned long, while currently only one byte > is passed from ima_hash_key(), which calculates a key for ima_htable. > > Given that hashing the digest does not give clear benefits compared to > using the digest itself, remove hash_long() and return the modulus > calculated on the first two bytes of the digest with the number of slots. > Also reduce the depth of the hash table by doubling the number of slots. > > Changelog > > v2: directly access the first two bytes of the digest to avoid memory > access issues on big endian systems (suggested by David Laight) > > Cc: stable@vger.kernel.org > Fixes: 3323eec921ef ("integrity: IMA as an integrity service provider") > Co-developed-by: Roberto Sassu > Signed-off-by: Roberto Sassu > Signed-off-by: Krzysztof Struczynski Acked-by: David.Laight@aculab.com > --- > security/integrity/ima/ima.h | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h > index 467dfdbea25c..02796473238b 100644 > --- a/security/integrity/ima/ima.h > +++ b/security/integrity/ima/ima.h > @@ -36,7 +36,7 @@ enum tpm_pcrs { TPM_PCR0 = 0, TPM_PCR8 = 8 }; > #define IMA_DIGEST_SIZE SHA1_DIGEST_SIZE > #define IMA_EVENT_NAME_LEN_MAX 255 > > -#define IMA_HASH_BITS 9 > +#define IMA_HASH_BITS 10 > #define IMA_MEASURE_HTABLE_SIZE (1 << IMA_HASH_BITS) > > #define IMA_TEMPLATE_FIELD_ID_MAX_LEN 16 > @@ -179,9 +179,10 @@ struct ima_h_table { > }; > extern struct ima_h_table ima_htable; > > -static inline unsigned long ima_hash_key(u8 *digest) > +static inline unsigned int ima_hash_key(u8 *digest) > { > - return hash_long(*digest, IMA_HASH_BITS); > + /* there is no point in taking a hash of part of a digest */ > + return (digest[0] | digest[1] << 8) % IMA_MEASURE_HTABLE_SIZE; > } > > #define __ima_hooks(hook) \ > -- > 2.17.1 - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)