Received: by 10.223.185.116 with SMTP id b49csp2281170wrg; Thu, 15 Feb 2018 09:12:21 -0800 (PST) X-Google-Smtp-Source: AH8x224tzjgpVqKCJyGHfU9Ac6Px+trOU4yI6RbvHTHZoGASsXlwjieMFCf5f4BtD8DGDoKGzQmn X-Received: by 2002:a17:902:9a41:: with SMTP id x1-v6mr3122694plv.256.1518714741520; Thu, 15 Feb 2018 09:12:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518714741; cv=none; d=google.com; s=arc-20160816; b=bUFVYgl03ieAXa7UwOPhR3Ib95yOIC9XKweHmnJBP2HtF39JN1yCsR32TSz5504D7L lROgfRrrwAduIGBYr7Gj5AnrkXsDPbpyNwF5GLmJEEQUn01mL8LQrqdIjci2M4QiznfU WZQj360eNnYDofNj3PytPQGwjc8sq7IplQWAcRVnAZBih6QRFXBcCu5wMVko5NLlZ/Nt 8WK3WgRu7nn204jKqb5+WMdaWP/9LFVfdjGGzVg5uLIkk4d/c2nCV+VU+hAa/SBZ0Kgw ZP0Zh9kBlaFcLf62p8RzCO3yqMB5+1lPMhKXMDoTBsrabH3qpn+pCjJFcqWSE21Y1Tde g4PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=jbb9VNpk1xuMWsqBgcVKHPdBoB9JY4q2nHOOCJMSV1Y=; b=wYO9xHNNtrVa14QgdUrCPzuxBt9xOAG+WlKc6csx1oJ52hIXqlPFZ7JFJyhyzBJrGP ZuJdUW0di+IDJWfrGieKHb8U9nqhM3C2SR8QDqt8zM2nSGMqXLtbLEhxcgldAu3/Hj2c 0D8yosMxMpAPz+V8QFI851PY8Eb3PV8Qn3f0Poxr9MVIYvA5Q7F7Ma65gqZvyhHLc7zp UxENmQ28v7U9yWaD0tIcb8KN9rcSsJwNAd0/3sQX9wVL9sILqhRc1cMdiFgxSRMBl8SX Uk3FqBAKhqzJ1Rp9BPM8+6UzmlztBEDGHM0R7qiT5Jq/6i7Ot0qrZMZR77uTWr91b9H8 3H/w== ARC-Authentication-Results: i=1; mx.google.com; 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 k9si679098pgc.628.2018.02.15.09.12.06; Thu, 15 Feb 2018 09:12:21 -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; 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 S1426930AbeBORKV (ORCPT + 99 others); Thu, 15 Feb 2018 12:10:21 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:59132 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422753AbeBOPhp (ORCPT ); Thu, 15 Feb 2018 10:37:45 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 940D0104D; Thu, 15 Feb 2018 15:37:44 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Benjamin Gaignard , Daniel Lezcano , Alexandre Torgue , Linus Torvalds , Maxime Coquelin , Peter Zijlstra , Thomas Gleixner , Ingo Molnar Subject: [PATCH 4.14 179/195] clocksource/drivers/stm32: Fix kernel panic with multiple timers Date: Thu, 15 Feb 2018 16:17:50 +0100 Message-Id: <20180215151715.162071962@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151705.738773577@linuxfoundation.org> References: <20180215151705.738773577@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Daniel Lezcano commit e0aeca3d8cbaea514eb98df1149faa918f9ec42d upstream. The current code hides a couple of bugs: - The global variable 'clock_event_ddata' is overwritten each time the init function is invoked. This is fixed with a kmemdup() instead of assigning the global variable. That prevents a memory corruption when several timers are defined in the DT. - The clockevent's event_handler is NULL if the time framework does not select the clockevent when registering it, this is fine but the init code generates in any case an interrupt leading to dereference this NULL pointer. The stm32 timer works with shadow registers, a mechanism to cache the registers. When a change is done in one buffered register, we need to artificially generate an event to force the timer to copy the content of the register to the shadowed register. The auto-reload register (ARR) is one of the shadowed register as well as the prescaler register (PSC), so in order to force the copy, we issue an event which in turn leads to an interrupt and the NULL dereference. This is fixed by inverting two lines where we clear the status register before enabling the update event interrupt. As this kernel crash is resulting from the combination of these two bugs, the fixes are grouped into a single patch. Tested-by: Benjamin Gaignard Signed-off-by: Daniel Lezcano Acked-by: Benjamin Gaignard Cc: Alexandre Torgue Cc: Linus Torvalds Cc: Maxime Coquelin Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/1515418139-23276-11-git-send-email-daniel.lezcano@linaro.org Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- drivers/clocksource/timer-stm32.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/drivers/clocksource/timer-stm32.c +++ b/drivers/clocksource/timer-stm32.c @@ -106,6 +106,10 @@ static int __init stm32_clockevent_init( unsigned long rate, max_delta; int irq, ret, bits, prescaler = 1; + data = kmemdup(&clock_event_ddata, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + clk = of_clk_get(np, 0); if (IS_ERR(clk)) { ret = PTR_ERR(clk); @@ -156,8 +160,8 @@ static int __init stm32_clockevent_init( writel_relaxed(prescaler - 1, data->base + TIM_PSC); writel_relaxed(TIM_EGR_UG, data->base + TIM_EGR); - writel_relaxed(TIM_DIER_UIE, data->base + TIM_DIER); writel_relaxed(0, data->base + TIM_SR); + writel_relaxed(TIM_DIER_UIE, data->base + TIM_DIER); data->periodic_top = DIV_ROUND_CLOSEST(rate, prescaler * HZ); @@ -184,6 +188,7 @@ err_iomap: err_clk_enable: clk_put(clk); err_clk_get: + kfree(data); return ret; }