Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp769547ybl; Wed, 11 Dec 2019 07:15:28 -0800 (PST) X-Google-Smtp-Source: APXvYqxwTTu46JHwEG0TTkZ7uTLrEez2vNimCzTUPZyffmIsFglt0fmtnjIv27IdYd0/XV3bBKam X-Received: by 2002:aca:52c7:: with SMTP id g190mr3035794oib.84.1576077328384; Wed, 11 Dec 2019 07:15:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576077328; cv=none; d=google.com; s=arc-20160816; b=NJ3StvwrHw0rf4jpGxp0szrd5gDZFzJyzEH59uj3P+qOgwdgOLW1ju+BKm+x3QTffd 1IxnAHtUv036yEPDxOsxrEBi2SOvA+xFcw8RWgLsb1yF7w1PIUDflPPAguV59Tch5mAo bRpLSZ7ePSxlxiASqHZEwiGk32boaoyT0HiHBSg31XgccrspJtNs1AjyVJPI02tKQUoO aY+Ga0BhEOvaoiEUmC5JLSf6AyX7af7MaRbsRpLmH3IBKKc62SrMdckYzHvdg/e5b3vi 0+hDs55cfejDjCDA4rrkSeW/D20RHEnystzTneE0k16/wQVhT537JodqES++31L9tRRQ pRNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RjR81QkhQYv19sOxqFt1wMuPFOEIEZCYoCmWCgMMF6Y=; b=MhVNLv2dtnLNoB4Ue7jf5Gyc2NtsYjOlBEgxIgwQtfQn7IBG00BkWlMp0pRpqqPyMk rgOz/ejIVZuld0lhuqOTX2qCuoq4Eo2bv6jLwuMfBDtptliAeDb1avXQwALE0loB1AD2 UUnm3w21UD9SDxhi2XH/KBZvJ6PtCTmLs3Kbd1phJChLqZt+1GU7iP8mWEYrcpMwzCv5 0uZoJrUDQGASnFFMUFxS3jCRoxE4XYOFIGa8NVlRq3+eCPair9f+A/dMzZ5igNUqq8+s CHDwaka5DKbj9fBmfU5vHmh6Ww/3b6NgOKq5MGYTONWKHf5mDsqw8Ghn9IPrN3YdIqt1 iVRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GTz5S2Pk; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u21si1192322otq.137.2019.12.11.07.15.16; Wed, 11 Dec 2019 07:15:28 -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=@kernel.org header.s=default header.b=GTz5S2Pk; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731604AbfLKPOO (ORCPT + 99 others); Wed, 11 Dec 2019 10:14:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:37134 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731427AbfLKPNb (ORCPT ); Wed, 11 Dec 2019 10:13:31 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E9B532465C; Wed, 11 Dec 2019 15:13:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077210; bh=cQnHYqMKMnTnO6m2mJKlDYRQy3IpoH92Ix9Topw/7fc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GTz5S2PkPIGoHm4VgVL0v2LmKciuqpdkqfIeWRYqWCVbKxFdBsQGa9SZcBtuIjTo9 3VRd61r32l6gKnDeyMuM6/0VrJ/1E4jJwIQX3cOaKLc1a3KovTPh6jJfPgmrPUKpiD /ITU/WkHs2kf9yz89sz7XbYz5y/6aRkRXWtEifwY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Leo Yan , Mathieu Poirier , Mike Leach Subject: [PATCH 5.3 059/105] coresight: etm4x: Fix input validation for sysfs. Date: Wed, 11 Dec 2019 16:05:48 +0100 Message-Id: <20191211150244.203826612@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mike Leach commit 2fe6899e36aa174abefd017887f9cfe0cb60c43a upstream. 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 Link: https://lore.kernel.org/r/20191104181251.26732-6-mathieu.poirier@linaro.org Signed-off-by: Greg Kroah-Hartman --- drivers/hwtracing/coresight/coresight-etm4x-sysfs.c | 21 ++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) --- a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c @@ -655,10 +655,13 @@ static ssize_t cyc_threshold_store(struc 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); @@ -689,14 +692,16 @@ static ssize_t bb_ctrl_store(struct devi 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); @@ -1329,8 +1334,8 @@ static ssize_t seq_event_store(struct de 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; } @@ -1585,7 +1590,7 @@ static ssize_t res_ctrl_store(struct 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; }