From patchwork Tue Jun 26 00:58:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 139902 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp4616758lji; Mon, 25 Jun 2018 18:00:37 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJNsnYk0kNcFtkPYvVwnOZT420bTFV6Aj84al4K9GnU7jSaCM7NKfhB7Mr8QDC8SppzBW0M X-Received: by 2002:a65:5307:: with SMTP id m7-v6mr7495934pgq.431.1529974837222; Mon, 25 Jun 2018 18:00:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529974837; cv=none; d=google.com; s=arc-20160816; b=HHPjFkAMD7emSW178XtPfBbI32AUL7nXKK0pEVPmuv0Sn1zlkskm7kEzd8IcgiFzGU jj3r31Y7rYtjNG5p5J2wWy82Ce1YlvUixGsstNMGW1x9vAuzYCV6+Hqz7cm5+zodACH4 nFPDK35S9I66pXP9zxv5RTwMmV0tzUbcV3zoMNIglvqY+2jWvY7Q0pnNg1jwdqV7txNZ S0tzkwkgv4A2PypfOX4i7s2O7+0cIzosEON313/sOjXRP/RU4Qdy8gDEFvs0+vk1cvVf MHNdNOd9aF+KC5FyKS4SCsSP+cJ+c4u5YnpOxsU3NCBChwDCurdxr5DSqI8qCsxMYxDX zGeg== 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=GyZkGlYZ1xYhCPBJ841az1JrzD/G85xn84STm/is5jU=; b=VNxCdo0bWvD5zUuV115itiTtAz9WMw206sXDcPexGUe01n3TEH38V6TKohVLmx7Pvm wtukXAurfi3s+94nb9U1eE0qz+tQN5adGZvmtQw8z4rm74Ob6yWrm8g8GoFNd4o4DpOT YhHLA4A7T0tl1/lAqi6ySaHUsMK0BllnYWIsOQQelgTzejmkGtvwEO1zEG/UKG4I+aUW evwzWN0Qy2sS03bIDs2Ek48xp/bnElZwxYFTso7URaK7EZXn/TakUqffYA3aDVJZpR9U xStQFUbGp8P2faG3zmn0JkEEEaxtbfQHCfX+MjVxV6M+JR/reJvyZ+CxGySztz5G8Of/ ylew== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=UAX6MZpp; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (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 g17-v6si310563plo.355.2018.06.25.18.00.37; Mon, 25 Jun 2018 18:00:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=UAX6MZpp; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934552AbeFZBAe (ORCPT + 13 others); Mon, 25 Jun 2018 21:00:34 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:55224 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755790AbeFZA7J (ORCPT ); Mon, 25 Jun 2018 20:59:09 -0400 Received: by mail-it0-f68.google.com with SMTP id 76-v6so15175072itx.4 for ; Mon, 25 Jun 2018 17:59:09 -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=ykWRwse3ZZFWvvwZIi1NRP2Kheq0JMqj14q6nMHsCMc=; b=UAX6MZppTydTMGxWWX8cy7zgQBwTSL8npUO3M79SWxNhgDT22eCvkE9/rj7Vat4+7V iixRVz7ODWBGE6ZiHPWbpK5YoVFDt3/BsNHJS5eqr3cupKFlRPF0xO/KLZeQNgcoswKc +FziDtZcCdhoTHBiEnqleNtI9t7ll3jutcfSI= 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=ykWRwse3ZZFWvvwZIi1NRP2Kheq0JMqj14q6nMHsCMc=; b=IvqsuU+Wk/sGXuw04qJ3wAeR70cc4WgnRKGiOphCRFO5LtbiHzni37E8yUwD6OuTnJ s/QraN0ksBcUjAscs+2ivnBNmb136iziG5eNiNVbV9TMFbkQ1UDGIZL+mttxva4EAlrb OzCdxZhCBlHsZUhZ+t1d80FEqPKDpHD0720eaYyP3SPHeGNo2aCXe39qBPwI9YuKSYhP JEtRmtW5nsBZtq9NEYM95EK06SiiepIqAo76HNsGZ2cLJ5s51ZB7eaKDlxE7ERKGpqFA UEvIEGczih8Q6yRONNtimTL6qPYeqPdUH7KpvqvnkpYaSkFOKY09+TjsIhlJ/I6l6G/4 tX9Q== X-Gm-Message-State: APt69E3IZcRFBe4HsuYdt9sc5oCr0/rydQYKeYcESnJlrd8nu3H8eflA AzQz/OwEVS1kBCUOh+JaKp5Uyg== X-Received: by 2002:a24:6e95:: with SMTP id w143-v6mr2726834itc.108.1529974748034; Mon, 25 Jun 2018 17:59:08 -0700 (PDT) Received: from localhost.localdomain (c-71-195-29-92.hsd1.mn.comcast.net. [71.195.29.92]) by smtp.gmail.com with ESMTPSA id f193-v6sm372556itf.9.2018.06.25.17.59.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Jun 2018 17:59:07 -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 resend 07/12] soc: qcom: smem: introduce qcom_smem_partition_header() Date: Mon, 25 Jun 2018 19:58:51 -0500 Message-Id: <20180626005856.14174-8-elder@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180626005856.14174-1-elder@linaro.org> References: <20180626005856.14174-1-elder@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Create a new function qcom_smem_partition_header() to encapsulate validating locating a partition header and validating information found within it. This will be built up over a few commits to make it more obvious how the common function is replacing duplicated code elsewhere. Initially it just verifies the header has the right magic number. Signed-off-by: Alex Elder --- drivers/soc/qcom/smem.c | 45 ++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 14 deletions(-) -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c index 49f228e9d2d3..516a17d340af 100644 --- a/drivers/soc/qcom/smem.c +++ b/drivers/soc/qcom/smem.c @@ -727,6 +727,29 @@ static u32 qcom_smem_get_item_count(struct qcom_smem *smem) return le16_to_cpu(info->num_items); } +/* + * Validate the partition header for a partition whose partition + * table entry is supplied. Returns a pointer to its header if + * valid, or a null pointer otherwise. + */ +static struct smem_partition_header * +qcom_smem_partition_header(struct qcom_smem *smem, + struct smem_ptable_entry *entry) +{ + struct smem_partition_header *header; + + header = smem->regions[0].virt_base + le32_to_cpu(entry->offset); + + if (memcmp(header->magic, SMEM_PART_MAGIC, sizeof(header->magic))) { + dev_err(smem->dev, "bad partition magic %02x %02x %02x %02x\n", + header->magic[0], header->magic[1], + header->magic[2], header->magic[3]); + return NULL; + } + + return header; +} + static int qcom_smem_set_global_partition(struct qcom_smem *smem) { struct smem_partition_header *header; @@ -760,15 +783,13 @@ static int qcom_smem_set_global_partition(struct qcom_smem *smem) return -EINVAL; } - header = smem->regions[0].virt_base + le32_to_cpu(entry->offset); + header = qcom_smem_partition_header(smem, entry); + if (!header) + return -EINVAL; + host0 = le16_to_cpu(header->host0); host1 = le16_to_cpu(header->host1); - if (memcmp(header->magic, SMEM_PART_MAGIC, sizeof(header->magic))) { - dev_err(smem->dev, "Global partition has invalid magic\n"); - return -EINVAL; - } - if (host0 != SMEM_GLOBAL_HOST || host1 != SMEM_GLOBAL_HOST) { dev_err(smem->dev, "Global partition hosts are invalid\n"); return -EINVAL; @@ -836,17 +857,13 @@ static int qcom_smem_enumerate_partitions(struct qcom_smem *smem, return -EINVAL; } - header = smem->regions[0].virt_base + le32_to_cpu(entry->offset); + header = qcom_smem_partition_header(smem, entry); + if (!header) + return -EINVAL; + host0 = le16_to_cpu(header->host0); host1 = le16_to_cpu(header->host1); - if (memcmp(header->magic, SMEM_PART_MAGIC, - sizeof(header->magic))) { - dev_err(smem->dev, - "Partition %d has invalid magic\n", i); - return -EINVAL; - } - if (host0 != host0 || host1 != host1) { dev_err(smem->dev, "Partition %d hosts don't match\n", i); From patchwork Tue Jun 26 00:58:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 139901 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp4616545lji; Mon, 25 Jun 2018 18:00:22 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLPaiaAlyLXze6Q4CPBYFVlKUOhh10M2tgHks4ojW7WfQMm8NQeW0KRHkyOfLFVK9zZCm6J X-Received: by 2002:a63:4346:: with SMTP id q67-v6mr12419718pga.328.1529974822017; Mon, 25 Jun 2018 18:00:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529974822; cv=none; d=google.com; s=arc-20160816; b=zsRBjcoTN+NzXVei3rh5FXeo7TL2uH1OM58sPMK0M6Kw5J8TvUuPkXz2WSDX0gVM5h uOpbX1X3eeV3uFqoHAofDXAUWt7NVBYp+aWB0OYBzqC2w1Bhytmn5Rw0TUxhnoBc3NOg bD1ZAwQi3ub4/122WUp6cROWDw4+1QfpSWzoJnjxXaIQI15VL6ygRBZuI6lJeaAVYL2X 9p4Z6n/WBz9FT26JfhCUtZkgg0CLrZjlvsHAIYDw7fZgJ+qLK8sLYq31dXC5/Ac5ciD8 wP23YB5SDPYlv6GKIaKoJ4+6Bj6g64jVL1yvYQl8FGbLRVd/TByR05ij5IowGhsa5CQb eqRg== 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=qQfRj7uf192FbUapBEgSRn41KtxQpeTGXwTk0wzHNL0=; b=GitizRSbdFbcT2k3efpic5RFrVz/SWKHXVRDm/py9ERwos4OXeHk9dGyKVQ4mmNOid QbVi8g47ePOd9I2JQ+6fbbr0TEQ5sAihBR+MrE8QjisGglErGXbVbgyPD+F0V6enJ5Gk 2CoA9QRqTzNAWxpb0ADaTrT4XXrqsmVqk+IfkC0AusayEDhNrutZnn+IuvUhVnGEsht1 bqMQ24LWl4PwEi/a7gNE9DfM8lNtxZZ9r2ERmYPGFjEGPpEEqGX2OQix/RFAJ1Te/Tv/ Vt1gbKpqe+W/OLzmMekM83uKjjkYNp8H8fRdlaUY1nt5c98yifZ+Q6bL760hS/HapiTB NtMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=MKfcOPco; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (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 w11-v6si270160pge.422.2018.06.25.18.00.21; Mon, 25 Jun 2018 18:00:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=MKfcOPco; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934869AbeFZBAU (ORCPT + 13 others); Mon, 25 Jun 2018 21:00:20 -0400 Received: from mail-it0-f67.google.com ([209.85.214.67]:33775 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755807AbeFZA7J (ORCPT ); Mon, 25 Jun 2018 20:59:09 -0400 Received: by mail-it0-f67.google.com with SMTP id k17-v6so13828757ita.0 for ; Mon, 25 Jun 2018 17:59:09 -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=kb0UYNwbePyrqiNt7GbnbXqyF1CVqdK0k2VzOr4z4tc=; b=MKfcOPcou+rP5ebOwGl3JSLih/nKY+mYyj6eXIhMPpoWYA1hqZeqlUj8aDr4yv6mVM i/ZLQDqRErALjCY/Ghl1D6xSW1Tpt1KJushEyEfhE+qsQDmAHskbyblcnDm6+iHxojLF qGpY+KTyxYKbDJoivQasLH0TWp67Mrw8p8HfU= 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=kb0UYNwbePyrqiNt7GbnbXqyF1CVqdK0k2VzOr4z4tc=; b=dNhNGu8icD5mPo/Mo3d8Bqvf3bgBHV4hQ73rtPA44GqJDWmLtf5RBg1leGEHTYMXT8 BlMcrj8Xi9/1gs1NNvT/BB9JyF1P9MiMOqZqZuC+sytFC1Kx/IcWuTLMco0IDNl7CMpr n1klJRsTqYF4oLN9DJRsmB13duqJTv6VW3skACqvCH3HIlA5caS/2JvL7DF1Kdp5uu94 sXKawg5LeoNhiTYKLhKGtSYg8UtyN/XBO8LbcgcTk5ASd6cegyIWMeLPHVAMDn4beTmi SXytwjX0zNTNBR1REYsF77A+qsCQEK09rgzk7+MKj7gWsyhrhUFK20SjUo8MIgg7ElPk 3KMw== X-Gm-Message-State: APt69E1Q3/51cI6yvemyyDhMlV/SB+Bb7pucPnOGBucNJxQ26rXRXa3X xwiVo131XmK6dlQnFGaLI6FMAw== X-Received: by 2002:a24:a0c2:: with SMTP id o185-v6mr2761337ite.34.1529974748959; Mon, 25 Jun 2018 17:59:08 -0700 (PDT) Received: from localhost.localdomain (c-71-195-29-92.hsd1.mn.comcast.net. [71.195.29.92]) by smtp.gmail.com with ESMTPSA id f193-v6sm372556itf.9.2018.06.25.17.59.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Jun 2018 17:59:08 -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 resend 08/12] soc: qcom: smem: verify partition header size Date: Mon, 25 Jun 2018 19:58:52 -0500 Message-Id: <20180626005856.14174-9-elder@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180626005856.14174-1-elder@linaro.org> References: <20180626005856.14174-1-elder@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Add verification in qcom_smem_partition_header() that the size in a partition's header structure matches the size in its partition table entry. Signed-off-by: Alex Elder --- drivers/soc/qcom/smem.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c index 516a17d340af..95d218d3a595 100644 --- a/drivers/soc/qcom/smem.c +++ b/drivers/soc/qcom/smem.c @@ -737,6 +737,7 @@ qcom_smem_partition_header(struct qcom_smem *smem, struct smem_ptable_entry *entry) { struct smem_partition_header *header; + u32 size; header = smem->regions[0].virt_base + le32_to_cpu(entry->offset); @@ -747,6 +748,13 @@ qcom_smem_partition_header(struct qcom_smem *smem, 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", + size, le32_to_cpu(entry->size)); + return NULL; + } + return header; } @@ -795,11 +803,6 @@ static int qcom_smem_set_global_partition(struct qcom_smem *smem) return -EINVAL; } - if (le32_to_cpu(header->size) != le32_to_cpu(entry->size)) { - dev_err(smem->dev, "Global partition has invalid size\n"); - return -EINVAL; - } - size = le32_to_cpu(header->offset_free_uncached); if (size > le32_to_cpu(header->size)) { dev_err(smem->dev, @@ -870,12 +873,6 @@ static int qcom_smem_enumerate_partitions(struct qcom_smem *smem, return -EINVAL; } - if (le32_to_cpu(header->size) != le32_to_cpu(entry->size)) { - dev_err(smem->dev, - "Partition %d has invalid size\n", i); - return -EINVAL; - } - if (le32_to_cpu(header->offset_free_uncached) > le32_to_cpu(header->size)) { dev_err(smem->dev, "Partition %d has invalid free pointer\n", i);