From patchwork Mon Nov 4 18:12:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 178469 Delivered-To: patch@linaro.org Received: by 2002:ac9:3c86:0:0:0:0:0 with SMTP id w6csp4389857ocf; Mon, 4 Nov 2019 10:13:48 -0800 (PST) X-Google-Smtp-Source: APXvYqyI7Jt3u9Za7f8pgIF2qSYWOlo2r0fF+Xqep/yIY19MOQXRIdEgRNiXFFVdss6maBVIqCJO X-Received: by 2002:a17:906:780e:: with SMTP id u14mr24629104ejm.97.1572891227994; Mon, 04 Nov 2019 10:13:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572891227; cv=none; d=google.com; s=arc-20160816; b=ReCQk06+Bhg1kr3UO4W/BC/suxGOce+Jkcxw9ELjxlEr6bU4WoExWIehCmvITJgfNO hXmW4QbqENSEFpSLDNrZsrCsc/S33SrHhF28OdJiOViFj7NYvYdyDkCsJZRi44MR2u6H nRh0fGnH2TDig4D+NYbqiHn4qwWH0mJUVu5Qt38fE5SfvLD1dzvXIhv43SWhYbNLCVx7 n4l22Uirokl+xReD8rqgEQD5v7/iK4of+dWjfWITkRdGhhvx1p6sWxl3RgvLcoxqgrbO UHE9EkRFiWMBaHVq/p2FtFe0dL/MeDk4C7Ly6pPBsHxBEVfQLx6iF7TR0sIu4PGC8/gd 0mkQ== 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; bh=my27JHtSw35YmWWmHWoHmAi4DXJc+0VoUXAKN5Q83qQ=; b=f2jyGj1i/bxoodZvfzRGFgwyybVeuSqenecNV6bbqW4Hu4ydroT2rXDY/jpAiumfue IfFV52bCqLbj1PTiHlMttBHi6TbYcEblXOQQDj49Bklbt6uBDrRAEjAEFOju3Hdan39m bN+lHLQ5daX1RcEOou4WdE/qaTjRkm3GPDGL8bc0gSoklD6Od3NT6VvH7E2WmobZqdNx 9Tw+3fKvT0Zhh9cn+eaCV+YERAbldFUzyjp/BBqzIvNN6WEgEKJBb+I/LAmTTPhrsM7z R6qqtAg3AC4fw9iyS8E9hMPRB3Mpl4s8/BsWaKLaqVxtf2x/0DByEjaXUKIZUJYcKa6G s+fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=z04j7Z2+; 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 d14si8315180ejc.72.2019.11.04.10.13.47; Mon, 04 Nov 2019 10:13:47 -0800 (PST) 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=z04j7Z2+; 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 S1729685AbfKDSNm (ORCPT + 26 others); Mon, 4 Nov 2019 13:13:42 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:35745 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729546AbfKDSM7 (ORCPT ); Mon, 4 Nov 2019 13:12:59 -0500 Received: by mail-pf1-f194.google.com with SMTP id d13so12853950pfq.2 for ; Mon, 04 Nov 2019 10:12:59 -0800 (PST) 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=my27JHtSw35YmWWmHWoHmAi4DXJc+0VoUXAKN5Q83qQ=; b=z04j7Z2+8CJTt3LDDdW0VKHsNjM427ulg1Fso6sALQXW8v87GYdFumTZ7klLVibxEO u3G+y2NH9jFQMLEt7KsjCEQA4m8ae69T56BnjtQLjDD6o24drb+6r7tkLlJcCvxPI6o8 VnUTGyZhug8t2LgkcTeeOZ+M1/3nFrEg0G7+1G2edZVz0UCTAWywDjC5fb79COINfgmo qAoLnJx3CQxoKGvRs8t9dFVwThrdoa7bRgJ2rAoZzuqiYu7izvP0JuLduGhaDzKWWMzG 8swo521Or6HZH3IbMWHAfwHUsrf5P3Lj9OdeSbipMpLXruapJlUzqDlhg8qLeRWdY/l9 4jGA== 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=my27JHtSw35YmWWmHWoHmAi4DXJc+0VoUXAKN5Q83qQ=; b=D323UOt1ctWQVOzLzY7yGArA2rjcM4eS8EAJybNzSL8VBOePTdE914K/REv1WK+o23 UQMZS5ozQTnPOHp4Ij753zdp5Ncpzbr87OMEqQcPdIQDpwO0SLaaRlU0rlJ7DO4C4XZs wKLnhIqzNqjmIxWuKNXKhac2CWmhZ2M9QKa1pq6m6m8i3WuU88rHNZkaMxg/NRKeF6gd BiZ9x3pNE77JnNDs16mmz/mlY1sDbnwIS1tbHsudPoFLsBI12MGrKoUy4x0k3fgWgSfk 3DCOsT357nELT8xubl9lWZ2dJ6OLqIAwmjQPJ5e4v39Hs55dFimzfjl+So6hbDBdhZTu fcFQ== X-Gm-Message-State: APjAAAUHG4jII0hQCSx2BP88UmttcLfyYq1oN3BmlwuwG+Fs3ol7UJzi +gY//V6/5MIvVcUq0L+C7rsrHg== X-Received: by 2002:a63:1e08:: with SMTP id e8mr10948373pge.336.1572891178635; Mon, 04 Nov 2019 10:12:58 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o12sm16149520pgl.86.2019.11.04.10.12.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2019 10:12:58 -0800 (PST) From: Mathieu Poirier To: gregkh@linuxfoundation.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/14] coresight: etm4x: Fix input validation for sysfs. Date: Mon, 4 Nov 2019 11:12:42 -0700 Message-Id: <20191104181251.26732-6-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191104181251.26732-1-mathieu.poirier@linaro.org> References: <20191104181251.26732-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mike Leach A number of issues are fixed relating to sysfs input validation:- 1) bb_ctrl_store() - incorrect compare of bit select field to absolute value. Reworked per ETMv4 specification. 2) seq_event_store() - incorrect mask value - register has two event values. 3) cyc_threshold_store() - must mask with max before checking min otherwise wrapped values can set illegal value below min. 4) res_ctrl_store() - update to mask off all res0 bits. Reviewed-by: Leo Yan Reviewed-by: Mathieu Poirier Signed-off-by: Mike Leach Fixes: a77de2637c9eb ("coresight: etm4x: moving sysFS entries to a dedicated file") Cc: stable # 4.9+ Signed-off-by: Mathieu Poirier --- .../coresight/coresight-etm4x-sysfs.c | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) -- 2.17.1 diff --git a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c index b6984be0c515..cc8156318018 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c @@ -652,10 +652,13 @@ static ssize_t cyc_threshold_store(struct device *dev, if (kstrtoul(buf, 16, &val)) return -EINVAL; + + /* mask off max threshold before checking min value */ + val &= ETM_CYC_THRESHOLD_MASK; if (val < drvdata->ccitmin) return -EINVAL; - config->ccctlr = val & ETM_CYC_THRESHOLD_MASK; + config->ccctlr = val; return size; } static DEVICE_ATTR_RW(cyc_threshold); @@ -686,14 +689,16 @@ static ssize_t bb_ctrl_store(struct device *dev, return -EINVAL; if (!drvdata->nr_addr_cmp) return -EINVAL; + /* - * Bit[7:0] selects which address range comparator is used for - * branch broadcast control. + * Bit[8] controls include(1) / exclude(0), bits[0-7] select + * individual range comparators. If include then at least 1 + * range must be selected. */ - if (BMVAL(val, 0, 7) > drvdata->nr_addr_cmp) + if ((val & BIT(8)) && (BMVAL(val, 0, 7) == 0)) return -EINVAL; - config->bb_ctrl = val; + config->bb_ctrl = val & GENMASK(8, 0); return size; } static DEVICE_ATTR_RW(bb_ctrl); @@ -1324,8 +1329,8 @@ static ssize_t seq_event_store(struct device *dev, spin_lock(&drvdata->spinlock); idx = config->seq_idx; - /* RST, bits[7:0] */ - config->seq_ctrl[idx] = val & 0xFF; + /* Seq control has two masks B[15:8] F[7:0] */ + config->seq_ctrl[idx] = val & 0xFFFF; spin_unlock(&drvdata->spinlock); return size; } @@ -1580,7 +1585,7 @@ static ssize_t res_ctrl_store(struct device *dev, if (idx % 2 != 0) /* PAIRINV, bit[21] */ val &= ~BIT(21); - config->res_ctrl[idx] = val; + config->res_ctrl[idx] = val & GENMASK(21, 0); spin_unlock(&drvdata->spinlock); return size; }