From patchwork Mon Dec 16 17:47:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 181757 Delivered-To: patch@linaro.org Received: by 2002:ac9:44c4:0:0:0:0:0 with SMTP id t4csp4619321och; Mon, 16 Dec 2019 09:55:51 -0800 (PST) X-Google-Smtp-Source: APXvYqxuCnbOhQHeJEHoLdbkHYmeCRoy1tv/iMeTZM5gB4nOgLa/iES9E/9ecL0dzW+fob7fCjJE X-Received: by 2002:a9d:6e12:: with SMTP id e18mr31251341otr.47.1576518951306; Mon, 16 Dec 2019 09:55:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576518951; cv=none; d=google.com; s=arc-20160816; b=R3X3qu78AIX2x5phH/k1erlniwCk1cOTxTIS6+fxlby3+3C816oF/NMdVE3leBcYyO SBFuN57Ui8q/UfDjuNKQvBkqwVq2+3hSymNQaLMUCvni4q24O7oNejWC8O90gP+Lz8Jh P0afFy1TlqsN9dmM0M26uf3lQHd5GN+truPdbpb2uIW8tKciKl5oadwAOtLcATU43Usw peIMRvX6f7KHCgEg6XW3+Q+KxOAP5EnGXRWOPEkwBxMiZXFNVBVJ5XP+s4+75HkD7vTT IJW7exwrAzQbvkzqR5cruYZ1fvUfD9G240LfULINtKGdlN/KRbj++UFqGkFuZcF0TVkR jrrg== 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=6yDiT31pLTZA5bGI/hzkeEKXQ+0nYjgT2FHD22Vga7Y=; b=MaUYXey4WhMFpNJ3IEnueLRetfF2wyQBBc4VJFppFGoTYpl9h+LCEyOsv0cIPKf7JI yrMJy7NH7yXQBB0XrhE8yBt0OHkYjucFR/RZOUYsO3MRxfQZs5Tyf7TVzX/KIVG8Fzy7 xneZRbblzRnPlYRlxKAePjBlZwFgzhKS2UFlAWF+drbitiqk2CC8rBRuhMoppHBD4sv/ G5kg7dbqs/3U9lhOQlxRFWRflwjmX0UvD06gEj9x9BNNESyZ2/uS7fOOSXQ0+7YV7Jo7 XGX1DAUhVIUnsAwu0aZABXHvtSMqc12+5oV9wUnRDjuz/KY9PvrNooL7H7N4pMOEVZAf 4HDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TZYqAloX; 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 r132si10773293oig.263.2019.12.16.09.55.51; Mon, 16 Dec 2019 09:55:51 -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=TZYqAloX; 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 S1727923AbfLPRzt (ORCPT + 27 others); Mon, 16 Dec 2019 12:55:49 -0500 Received: from mail.kernel.org ([198.145.29.99]:53196 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728074AbfLPRzp (ORCPT ); Mon, 16 Dec 2019 12:55:45 -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 370492176D; Mon, 16 Dec 2019 17:55:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576518944; bh=cvPAg9I2YwVLNkWL6x0/cKoqr1AmKIBCDJShQFg1R7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TZYqAloXdJsD6O/mVSJ5rS2gnuKzoHMZCp2NOLlQEYcOtuQ3MENUpyWBxUfZ7tOwF FAL+1y/sJKvR95o2HRgYfK4lSwMNEWyys+e1U0ekXY+QcnuWmRgkHsvxHD+uKv2dQG wk9lIP5lMSI1w2B/XGyGXe7LJAX6hqZ2Lb+tWP4Q= 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 4.14 130/267] coresight: etm4x: Fix input validation for sysfs. Date: Mon, 16 Dec 2019 18:47:36 +0100 Message-Id: <20191216174906.442408533@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191216174848.701533383@linuxfoundation.org> References: <20191216174848.701533383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 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 @@ -667,10 +667,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); @@ -701,14 +704,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); @@ -1341,8 +1346,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; } @@ -1597,7 +1602,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; }