From patchwork Wed May 2 01:10:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 134807 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp124721lji; Tue, 1 May 2018 18:11:57 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq7wBuMKFIFYD5IFHuxrdonadXNtpGG36eySCEi7bdgulnrBoa0m28ZQDOKAveFuGrk5T9s X-Received: by 2002:a17:902:6b45:: with SMTP id g5-v6mr3489400plt.67.1525223517584; Tue, 01 May 2018 18:11:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525223517; cv=none; d=google.com; s=arc-20160816; b=Pwh4jjXl2/yiaNlorMhZoO0K8bn+4i+c6V3g8GKuC+jyLMwrMxtesmV4IhJzKm8wxc GLcc5vou3c6Yt42xIq7hCHDT9L2NTpHYGCwMd7wQrhqSxUbC47tiE3oNgr2/YslEQxNG Or7W61v+L1gzhl9jR5HBfEm/liU/cFkUWluKSg8kHo181WrvvG8btXKkwar6TxsqhDO8 zITnkYkWEJMW0rtQXtaBKgdaSSFQIlxrhiChYcnQtkrnXBNGen51CKWEo5L3JBdAQiKb K0L5+8Yl++cgSTP6YLCb5PGH1bCAhBjt8SfC2YsXiTEQFuQ9X1JZH8CTHUC1CumOyuba A2EA== 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=znptUnZx0R3NadRdMSznhIujdZEya1BwEJm1jhWK1Dc=; b=BeFJjx3S88hxw7+s5SeQRet4Ue2Mx4s1v/OPJb5eOfug8tVL7q8i2yf4Hg9Hevf5el As6cpZIpkHJo+0gQotJggt12yUpkegMJhXd1Pxod1NRTgaZlYcdSLGDUgMkcPusXKVF4 ly+6LhzSNZ9x9OqoKtYH20L7J69QQ+MoImlp7xpCPTMqIwt0nIhGaFpN/4b11JhMRKpu lDGyzheZaLyZ2KrlCdYyqt4gmrDZnuBR97KAMnWhDG8B3jbWpkRpqD0SPU4ScBX365lS ku7xY/56Tqx06B7SEickePF3WCMR99McrH4yMzYzyiES2K7bIGiBUpt2TUNaor3QpvI9 Eh1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SWRSZnGh; 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 z9-v6si4495461plk.94.2018.05.01.18.11.57; Tue, 01 May 2018 18:11:57 -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=SWRSZnGh; 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 S1751499AbeEBBLy (ORCPT + 29 others); Tue, 1 May 2018 21:11:54 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:40990 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751269AbeEBBKh (ORCPT ); Tue, 1 May 2018 21:10:37 -0400 Received: by mail-io0-f196.google.com with SMTP id e12-v6so15579704iob.8 for ; Tue, 01 May 2018 18:10:36 -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=znptUnZx0R3NadRdMSznhIujdZEya1BwEJm1jhWK1Dc=; b=SWRSZnGhkqlZc8cJP2An+L6lZEUjb6kx7y66u5Hg42X9pO6/F8CFZCUhWdC55Fquky LAjjM0hrDHcIfwCnyzBnxUv+StM7YhX1kWQhroJYUUKv5E9idew+BrrfpRcvDpQJaxNw cEMogZ5eXmdNXbsiuDEAX/aX+o1FS85e19pkk= 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=znptUnZx0R3NadRdMSznhIujdZEya1BwEJm1jhWK1Dc=; b=r2jTq7z+88ST4TOlHwBfY1C59Iuy8aCvGk7EAIKSbDEAWHRfK2tu6Ca8MwNVC49/6M I0iYDU1yFo9f5jRGacsJM6E8vQF4Myp6j737OcNzdliADYJFczPI4lSbsDHkaiWC8P64 5BcjmLV/kBuddiEOl7OYJMPKVCpjk2QxVU9IJ/oRyGlYfFHJb9vZ+7ccmT7tWPPEu3a0 xjMPo0cpsoHIApYNifUSYjx3KUTtgzL0Xn9J8S4Y+tQzTXn7kik903fv+SpWS/AI1+tn XiMzg4oiLDHqtcD1jCukXG35DmTT8z4hZWb1baImT6FNhUfiMu6QTzOaqM2yJ2vTbpy9 kszw== X-Gm-Message-State: ALQs6tCjaFkJXOIonIo4rNy87kByOJuqL+YCnC3UyzBYkYgsUNQ1vWWd uKnofc03+VrjIxCtq/uTeW2+Gg== X-Received: by 2002:a6b:aae0:: with SMTP id g93-v6mr18745669ioj.202.1525223436540; Tue, 01 May 2018 18:10:36 -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.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 May 2018 18:10:36 -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 09/12] soc: qcom: smem: verify partition offset_free_uncached Date: Tue, 1 May 2018 20:10:16 -0500 Message-Id: <20180502011019.22812-10-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 offset_free_uncached field in a partition's header structure does not exceed the partition's size. Signed-off-by: Alex Elder --- drivers/soc/qcom/smem.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) -- 2.14.1 diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c index f1e6e4609ccb..7ef415c4d62e 100644 --- a/drivers/soc/qcom/smem.c +++ b/drivers/soc/qcom/smem.c @@ -755,6 +755,12 @@ qcom_smem_partition_header(struct qcom_smem *smem, return NULL; } + if (le32_to_cpu(header->offset_free_uncached) > size) { + dev_err(smem->dev, "bad partition free uncached (%u > %u)\n", + le32_to_cpu(header->offset_free_uncached), size); + return NULL; + } + return header; } @@ -763,7 +769,7 @@ 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, size; + u32 host0, host1; bool found = false; int i; @@ -803,13 +809,6 @@ static int qcom_smem_set_global_partition(struct qcom_smem *smem) return -EINVAL; } - size = le32_to_cpu(header->offset_free_uncached); - if (size > le32_to_cpu(header->size)) { - dev_err(smem->dev, - "Global partition has invalid free pointer\n"); - return -EINVAL; - } - smem->global_partition = header; smem->global_cacheline = le32_to_cpu(entry->cacheline); @@ -871,12 +870,6 @@ static int qcom_smem_enumerate_partitions(struct qcom_smem *smem, 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); - return -EINVAL; - } - smem->partitions[remote_host] = header; smem->cacheline[remote_host] = le32_to_cpu(entry->cacheline); }