Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4541533pxj; Tue, 8 Jun 2021 17:27:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuuTrKV7qpqYwEuU56RZsMTXlomxzGVJMGcCMFkeIiqq3y8fx+R4lYVN+53a65k4jMPf++ X-Received: by 2002:a17:906:4ac4:: with SMTP id u4mr25105753ejt.229.1623198463574; Tue, 08 Jun 2021 17:27:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623198463; cv=none; d=google.com; s=arc-20160816; b=eDXxiT246etJX5PFkLYj5ffbLREwiBWBlHnBrsTKTNzcxozzJd0K9rWOLUig8YnfJl 13VeqmSa91pyxTMDpcVzd7+8oQiU5XgMBMijCFURddD2+7a99IpojirE6CEzyktecl0w 3akXSQ/N3bH5hNWWxw9vIWXtE8NFcs2AWYnGMZSlw4E9b35e4D8ElkbbuCnheQTGMKJ4 IgEhvc9R4W61zYEGZSSJSRoKRC/LqikZBzmLLnqedT1DX+2o0oNYF7rVCOyOQUsaKRa1 0hCqwAaYq7ZPm7CcAftLms7C4Vfsgbh22ReYx90bh23Bpm0bovhHVTTg0XcOJTU0vN90 9zbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=KNn4CAp3wlocJCs7vjk0F8dWKo7WNw7oFJI5fmpuHOQ=; b=T1n7t+/FSi0RmQ9mR+xe3aVZTQLJMXGegkpF7LWOSxx97b7UOxDH032jnqSuSCFbC1 /pIG20fyuRZ4Ps/KaDeOsFKHcCWH7a6F8zACegnYzUOVRO2gqUpe3Sx++XkeGWmf5Q0f zMNxRywd1t39BwI3+s+138uxTc16Bg2kzlqhuRVoe1uNMxdsbi9P5vpZrOLDt/lrsuI+ gfPiWdv4jdP+S4kgB6Xx550qoexzNrUJveGcHffU+Uy/nMJ+1GilS8qPNe3vTa4+GPCz ut/k/icJyvvPKb7HloLzB0u8jhP9237YDWhdn50jlz+jr2ApeWtV6jqr4xtt0FWgVYUK QZaQ== 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=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i27si921367ejh.691.2021.06.08.17.27.20; Tue, 08 Jun 2021 17:27:43 -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=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232738AbhFHMeI (ORCPT + 99 others); Tue, 8 Jun 2021 08:34:08 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3172 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232607AbhFHMd6 (ORCPT ); Tue, 8 Jun 2021 08:33:58 -0400 Received: from fraeml714-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4FzqFY2jYhz6G7Wk; Tue, 8 Jun 2021 20:25:21 +0800 (CST) Received: from roberto-ThinkStation-P620.huawei.com (10.204.62.217) by fraeml714-chm.china.huawei.com (10.206.15.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Tue, 8 Jun 2021 14:32:00 +0200 From: Roberto Sassu To: , CC: , , , , , Roberto Sassu , kernel test robot Subject: [PATCH 2/5] ima: Set correct casting types Date: Tue, 8 Jun 2021 14:31:21 +0200 Message-ID: <20210608123124.335868-2-roberto.sassu@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210608123124.335868-1-roberto.sassu@huawei.com> References: <20210608123124.335868-1-roberto.sassu@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.204.62.217] X-ClientProxiedBy: lhreml753-chm.china.huawei.com (10.201.108.203) To fraeml714-chm.china.huawei.com (10.206.15.33) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The code expects that the values being parsed from a buffer when the ima_canonical_fmt global variable is true are in little endian. Thus, this patch sets the casting types accordingly. Reported-by: kernel test robot Signed-off-by: Roberto Sassu --- security/integrity/ima/ima_template.c | 8 ++++---- security/integrity/ima/ima_template_lib.c | 11 ++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/security/integrity/ima/ima_template.c b/security/integrity/ima/ima_template.c index a85963853a91..694560396be0 100644 --- a/security/integrity/ima/ima_template.c +++ b/security/integrity/ima/ima_template.c @@ -423,9 +423,9 @@ int ima_restore_measurement_list(loff_t size, void *buf) return 0; if (ima_canonical_fmt) { - khdr->version = le16_to_cpu(khdr->version); - khdr->count = le64_to_cpu(khdr->count); - khdr->buffer_size = le64_to_cpu(khdr->buffer_size); + khdr->version = le16_to_cpu((__force __le16)khdr->version); + khdr->count = le64_to_cpu((__force __le64)khdr->count); + khdr->buffer_size = le64_to_cpu((__force __le64)khdr->buffer_size); } if (khdr->version != 1) { @@ -515,7 +515,7 @@ int ima_restore_measurement_list(loff_t size, void *buf) } entry->pcr = !ima_canonical_fmt ? *(u32 *)(hdr[HDR_PCR].data) : - le32_to_cpu(*(u32 *)(hdr[HDR_PCR].data)); + le32_to_cpu(*(__le32 *)(hdr[HDR_PCR].data)); ret = ima_restore_measurement_entry(entry); if (ret < 0) break; diff --git a/security/integrity/ima/ima_template_lib.c b/security/integrity/ima/ima_template_lib.c index 518fd50ea48a..3f8d53a03612 100644 --- a/security/integrity/ima/ima_template_lib.c +++ b/security/integrity/ima/ima_template_lib.c @@ -98,21 +98,21 @@ static void ima_show_template_data_ascii(struct seq_file *m, case sizeof(u16): if (ima_canonical_fmt) seq_printf(m, "%u", - le16_to_cpu(*(u16 *)buf_ptr)); + le16_to_cpu(*(__le16 *)buf_ptr)); else seq_printf(m, "%u", *(u16 *)buf_ptr); break; case sizeof(u32): if (ima_canonical_fmt) seq_printf(m, "%u", - le32_to_cpu(*(u32 *)buf_ptr)); + le32_to_cpu(*(__le32 *)buf_ptr)); else seq_printf(m, "%u", *(u32 *)buf_ptr); break; case sizeof(u64): if (ima_canonical_fmt) seq_printf(m, "%llu", - le64_to_cpu(*(u64 *)buf_ptr)); + le64_to_cpu(*(__le64 *)buf_ptr)); else seq_printf(m, "%llu", *(u64 *)buf_ptr); break; @@ -226,9 +226,10 @@ int ima_parse_buf(void *bufstartp, void *bufendp, void **bufcurp, if (bufp > (bufendp - sizeof(u32))) break; - fields[i].len = *(u32 *)bufp; if (ima_canonical_fmt) - fields[i].len = le32_to_cpu(fields[i].len); + fields[i].len = le32_to_cpu(*(__le32 *)bufp); + else + fields[i].len = *(u32 *)bufp; bufp += sizeof(u32); } -- 2.25.1