From patchwork Wed May 2 01:10:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 134805 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp124220lji; Tue, 1 May 2018 18:11:14 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrtWiEbyHPJkXgrAQoNWUjF2TQa4vxCGFfESVc9nLTWYF2V27dhTgWVAM51SUB/6LkPOyQ3 X-Received: by 10.167.129.204 with SMTP id c12mr4873952pfn.169.1525223474087; Tue, 01 May 2018 18:11:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525223474; cv=none; d=google.com; s=arc-20160816; b=DEVPheATMoidhC5vG5nonl58KuoAhUCg+KBKtggJSQ2b5oLpRDOLJubX27v+SFru8a 8oge1MCoO8t9FNkAUHDb6yh41Swz0MXSSH2/80CSwq2dVcF/GZWlQyvmq6t2pIxP1dM5 hlHHw+cyNujtczI13qBpznL5CJosbFi4ZSRY2or5+8hNsGI5tKiukyRbtlhavMAQxun7 UzcWIqrh84lh7Drmwlmh3egDJQkndHdU5mXKKXsW4pIzT8nCquGCloP/Zibm7GaJB5zP ixcXQj0mMLVnwErbKvc9xqOqEbu+v4RvSbmhwGlKEupHcj9AJF2P3DOW9qq00BVnyAyi Vq1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=0N7mqW0MP/CZKS+2sfMTDlQv7tC8kl8APpV2SbuO4fA=; b=HL6OfAXUp805bABi/v31dGCggPExaDWV6um2bFBqaatA8gYqiOwwvJWo3BGGKYfHbS X/0wS7USlXkzcdRW06WCFLWRvM1VEKIoE8xiP4gnai2R6ly3Xms5ZD3ZbRLIx2yZjjJp LAqwL/Qb4v2Daf4wEzxO1lhEr2VJ6M2a1/5r3kkPce5vpkdXMOs9dCZMX90MIorNJqJB 8SqgFHPwRr7nrW7ZCCZPSuGyhRh2XU7zK6OL5L2ZrtpB6STrxHGFwQy/I3VIbIlQEULa u8dSOi7RZkLuoZabhuvkTm5VuRVlUdWGMRsPcR1Wv4TajLUf0C+//gSbXFApJgTlKFKb SAgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SBLt1gi7; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i10-v6si8554601pgs.239.2018.05.01.18.11.13; Tue, 01 May 2018 18:11:14 -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=@linaro.org header.s=google header.b=SBLt1gi7; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751426AbeEBBLL (ORCPT + 29 others); Tue, 1 May 2018 21:11:11 -0400 Received: from mail-it0-f65.google.com ([209.85.214.65]:55628 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751174AbeEBBKj (ORCPT ); Tue, 1 May 2018 21:10:39 -0400 Received: by mail-it0-f65.google.com with SMTP id 144-v6so15574747iti.5 for ; Tue, 01 May 2018 18:10:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0N7mqW0MP/CZKS+2sfMTDlQv7tC8kl8APpV2SbuO4fA=; b=SBLt1gi7WF/nnkoxxCnii08PqC5WCVS28zV2LzyI2Sw56wGa7FFbQ6+ySNf4MKgFOG g8STWG0ntEsX+WqZBeFUwitAhcMRU5/zc5NtGT9/4wquo6x4USL4rGo2XB/xrbN/Glzb 1IJmUmgapTe39o/dD6zz/xboZlC0zk+pN8wqU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0N7mqW0MP/CZKS+2sfMTDlQv7tC8kl8APpV2SbuO4fA=; b=dvmsLgdoaYQI4uX7Sk96pi8g3rTWZR68m20VLSB+Ilj1XTMpv9FTIliVjDbouWi3Bn diMOYyboZl5vJFLHjHOztXhEseSxBGnuT8bqqHqFuu/VHkKkAGLlCyrbh62hG9FzHhTX Bl4DvVq749UU1RiYxIqq0KBBqdmtr+y2sK16JwLqdUfjbmSGRmim1HJzb57yTXesVT3F TNajrkhP+7bDVUPNF3M8/sQntcX2os6tpxmnSRuN0Dxi2NrObRjuBtypS+wcYZJpIQWQ OC2iusmWmXDoZYvpaBiY8Qg9IY0q6oU8ZnuvtsDxSU88r6Iy2EwNGXpzVSWXU6+9auDK vleg== X-Gm-Message-State: ALQs6tAl+ZJRJniL+Q5cqCJPKEsD6lmam4sX4mLfd+VFgy1d2DFizX4j caS7zXUAUFMKkSRWMg6hWircIg== X-Received: by 2002:a24:fdc9:: with SMTP id m192-v6mr17033066ith.95.1525223438430; Tue, 01 May 2018 18:10:38 -0700 (PDT) Received: from presto.localdomain (c-71-195-29-92.hsd1.mn.comcast.net. [71.195.29.92]) by smtp.gmail.com with ESMTPSA id g200-v6sm2082479itb.26.2018.05.01.18.10.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 May 2018 18:10:37 -0700 (PDT) From: Alex Elder To: andy.gross@linaro.org Cc: clew@codeaurora.org, aneela@codeaurora.org, david.brown@linaro.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 11/12] soc: qcom: smem: verify partition host ids match Date: Tue, 1 May 2018 20:10:18 -0500 Message-Id: <20180502011019.22812-12-elder@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180502011019.22812-1-elder@linaro.org> References: <20180502011019.22812-1-elder@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add verification in qcom_smem_partition_header() that the host ids found in a partition's header structure match those in its partition table entry. Signed-off-by: Alex Elder --- drivers/soc/qcom/smem.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) -- 2.14.1 diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c index 54c504e41508..7383a0e1b468 100644 --- a/drivers/soc/qcom/smem.c +++ b/drivers/soc/qcom/smem.c @@ -734,7 +734,7 @@ static u32 qcom_smem_get_item_count(struct qcom_smem *smem) */ static struct smem_partition_header * qcom_smem_partition_header(struct qcom_smem *smem, - struct smem_ptable_entry *entry) + struct smem_ptable_entry *entry, u16 host0, u16 host1) { struct smem_partition_header *header; u32 size; @@ -748,6 +748,17 @@ qcom_smem_partition_header(struct qcom_smem *smem, return NULL; } + if (host0 != le16_to_cpu(header->host0)) { + dev_err(smem->dev, "bad host0 (%hu != %hu)\n", + host0, le16_to_cpu(header->host0)); + return NULL; + } + if (host1 != le16_to_cpu(header->host1)) { + dev_err(smem->dev, "bad host1 (%hu != %hu)\n", + host1, le16_to_cpu(header->host1)); + return NULL; + } + size = le32_to_cpu(header->size); if (size != le32_to_cpu(entry->size)) { dev_err(smem->dev, "bad partition size (%u != %u)\n", @@ -769,7 +780,6 @@ static int qcom_smem_set_global_partition(struct qcom_smem *smem) struct smem_partition_header *header; struct smem_ptable_entry *entry; struct smem_ptable *ptable; - u32 host0, host1; bool found = false; int i; @@ -798,18 +808,11 @@ static int qcom_smem_set_global_partition(struct qcom_smem *smem) return -EINVAL; } - header = qcom_smem_partition_header(smem, entry); + header = qcom_smem_partition_header(smem, entry, + SMEM_GLOBAL_HOST, SMEM_GLOBAL_HOST); if (!header) return -EINVAL; - host0 = le16_to_cpu(header->host0); - host1 = le16_to_cpu(header->host1); - - if (host0 != SMEM_GLOBAL_HOST || host1 != SMEM_GLOBAL_HOST) { - dev_err(smem->dev, "Global partition hosts are invalid\n"); - return -EINVAL; - } - smem->global_partition = header; smem->global_cacheline = le32_to_cpu(entry->cacheline); @@ -860,17 +863,10 @@ static int qcom_smem_enumerate_partitions(struct qcom_smem *smem, return -EINVAL; } - header = qcom_smem_partition_header(smem, entry); + header = qcom_smem_partition_header(smem, entry, host0, host1); if (!header) return -EINVAL; - if (host0 != le16_to_cpu(header->host0) || - host1 != le16_to_cpu(header->host1)) { - dev_err(smem->dev, - "Partition %d hosts don't match\n", i); - return -EINVAL; - } - smem->partitions[remote_host] = header; smem->cacheline[remote_host] = le32_to_cpu(entry->cacheline); }