Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13476608ybl; Sun, 29 Dec 2019 12:50:13 -0800 (PST) X-Google-Smtp-Source: APXvYqz4whlsoAYMMaJ8DUXE84P4Fx//vHpM8woPRqJKrATw/Rwlbq5pFHraM9dPY0/Gyrk4/taj X-Received: by 2002:a9d:6b06:: with SMTP id g6mr61491434otp.93.1577652613212; Sun, 29 Dec 2019 12:50:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577652613; cv=none; d=google.com; s=arc-20160816; b=afVr+5061HBFUMOIBLB0qama/C+rk1NxQV12+ptJZ0Tz6rPbhTqWJluCrnPVhRx7Ce j9UW7BcpU0BPLqwHJBMgLSEtGkcIHDEyqKrcXVQ6E1UhaOUXEwvh94hzT61vhNVqiXP3 45F4IU02x0p/55mcDsPdI/e2Q/Erz1ZM/NOvr0U0OejQejzfBaGwMpY2T8YWrZNiXB+e ST4zG57D+zIPYucjbZL+Myqs1uikSjKxoMOTMQu0MaPpS4Dyc+tel/LBmkAZf8txwptO VhNv7Jz74RQu9aB2W3XsoLetdf8SOr0Zgb83dRRGgYawQSupBQd2d99kTUEqLeCKi+Ws qSNA== 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=fTrwY1uIJFkuAKXvqVGdwtbccdMgYTFeLFSw6WbXDXg=; b=mo0rRX9iPknssEossxaHaS39BXrqLtl/UATYJS3UrCozhiSdfK/U+d4U1MdP5gCaeH SqKXHDx6f7xEv5gyFhIQ7mF+aK1SVS4aZ6JF4MWyx0AxCXMv2TPV6wQV+M1dOWz49DaL kpWWn/jiItL1S6wyk4AeJg0EuqE4zAdKyrxlyNNs3wj1V/ouHtL9XPn92rhs7qMZFcZQ ygdgJ/o4uObdAf3rAXHHhcXPpTGy9XWufbUSTBoKfDIDA2PYrvvHk9aFgoe9To23yzaj mokuvyjeUI2XiAl3lUJ7p4U79JWaGrl2BnKgLU3f6VLG/5YajakRVcNGQIfd6IYnfhiz Bxvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Y8V9ijcF; 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 r14si18415086oic.12.2019.12.29.12.50.02; Sun, 29 Dec 2019 12:50:13 -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=Y8V9ijcF; 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 S1732796AbfL2R51 (ORCPT + 99 others); Sun, 29 Dec 2019 12:57:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:47906 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732963AbfL2R5Z (ORCPT ); Sun, 29 Dec 2019 12:57:25 -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 189B121744; Sun, 29 Dec 2019 17:57:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577642244; bh=tLimZJIgN2Fma8fEKXPYFx7UStdsZvk3pJGF5ppdUDg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y8V9ijcFHlM3duXG3otxy1SxxAHdvrryX3Niazv5e1XReAaPa25+W5pJLTw841l6w VyXS6/JO9Nae82w12sh3GzPTTzUhHU2qFONzQjrCRI/0MREtczdX498qHSE4y8LrYy AZ0BybLjbxLm5vpD1KLPGX//gKbEVKrbnSNq0Op0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Shishkin , Andy Shevchenko , Ammy Yi Subject: [PATCH 5.4 401/434] intel_th: msu: Fix window switching without windows Date: Sun, 29 Dec 2019 18:27:34 +0100 Message-Id: <20191229172729.149072010@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229172702.393141737@linuxfoundation.org> References: <20191229172702.393141737@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: Alexander Shishkin commit 05b686b573cfb35a227c30787083a6631ff0f0c9 upstream. Commit 6cac7866c2741 ("intel_th: msu: Add a sysfs attribute to trigger window switch") adds a NULL pointer dereference in the case when there are no windows allocated: > BUG: kernel NULL pointer dereference, address: 0000000000000000 > #PF: supervisor read access in kernel mode > #PF: error_code(0x0000) - not-present page > PGD 0 P4D 0 > Oops: 0000 1 SMP > CPU: 5 PID: 1110 Comm: bash Not tainted 5.5.0-rc1+ #1 > RIP: 0010:msc_win_switch+0xa/0x80 [intel_th_msu] > Call Trace: > ? win_switch_store+0x9b/0xc0 [intel_th_msu] > dev_attr_store+0x17/0x30 > sysfs_kf_write+0x3e/0x50 > kernfs_fop_write+0xda/0x1b0 > __vfs_write+0x1b/0x40 > vfs_write+0xb9/0x1a0 > ksys_write+0x67/0xe0 > __x64_sys_write+0x1a/0x20 > do_syscall_64+0x57/0x1d0 > entry_SYSCALL_64_after_hwframe+0x44/0xa9 Fix that by disallowing window switching with multiwindow buffers without windows. Signed-off-by: Alexander Shishkin Fixes: 6cac7866c274 ("intel_th: msu: Add a sysfs attribute to trigger window switch") Reviewed-by: Andy Shevchenko Reported-by: Ammy Yi Tested-by: Ammy Yi Cc: stable@vger.kernel.org # v5.2+ Link: https://lore.kernel.org/r/20191217115527.74383-5-alexander.shishkin@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/hwtracing/intel_th/msu.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) --- a/drivers/hwtracing/intel_th/msu.c +++ b/drivers/hwtracing/intel_th/msu.c @@ -1676,10 +1676,13 @@ static int intel_th_msc_init(struct msc return 0; } -static void msc_win_switch(struct msc *msc) +static int msc_win_switch(struct msc *msc) { struct msc_window *first; + if (list_empty(&msc->win_list)) + return -EINVAL; + first = list_first_entry(&msc->win_list, struct msc_window, entry); if (msc_is_last_win(msc->cur_win)) @@ -1691,6 +1694,8 @@ static void msc_win_switch(struct msc *m msc->base_addr = msc_win_base_dma(msc->cur_win); intel_th_trace_switch(msc->thdev); + + return 0; } /** @@ -2025,16 +2030,15 @@ win_switch_store(struct device *dev, str if (val != 1) return -EINVAL; + ret = -EINVAL; mutex_lock(&msc->buf_mutex); /* * Window switch can only happen in the "multi" mode. * If a external buffer is engaged, they have the full * control over window switching. */ - if (msc->mode != MSC_MODE_MULTI || msc->mbuf) - ret = -ENOTSUPP; - else - msc_win_switch(msc); + if (msc->mode == MSC_MODE_MULTI && !msc->mbuf) + ret = msc_win_switch(msc); mutex_unlock(&msc->buf_mutex); return ret ? ret : size;