From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC9C4C4363D for ; Thu, 24 Sep 2020 20:13:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8696523899 for ; Thu, 24 Sep 2020 20:13:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="frWGjDFQ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="2j+GXwjj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726597AbgIXUN5 (ORCPT ); Thu, 24 Sep 2020 16:13:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726037AbgIXUN5 (ORCPT ); Thu, 24 Sep 2020 16:13:57 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFB2FC0613CE; Thu, 24 Sep 2020 13:13:56 -0700 (PDT) Date: Thu, 24 Sep 2020 20:13:54 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1600978435; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b0p/stKwtIhcp5+uygcPVT0jPD8tZbpQyj2KTq05TCI=; b=frWGjDFQ/pTE1qB8JKwQ9yFvrV8fRVrVjRy4JBYlJTD/awZw6ff/9siXOJpGti8cWyoZNu 3H636xE0qHx4C3pAAqtpMXuS37L6i5ZTTWyeSsD01I7DDlWH7pQKQo8+AnMHNP6Mmj9PqP qO6eo6hjXpqvDl9y+TRBwXZ7Fv95hGj1l638oZMDhLEAvQveTeINFVjnBW84dMz5a+2Tev PIwVZbPuBhMkD7QYDK5su938UKM0F99Dk9LJgaKOAbRMRfAZgEHqHJBORMpHWuCbm0TD7T r6k6AA9vIdd1FlQqdfQdDWsqIrYSsJIfio3aMWW74ULPgFxBLEeaPx8dNsDQGQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1600978435; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b0p/stKwtIhcp5+uygcPVT0jPD8tZbpQyj2KTq05TCI=; b=2j+GXwjj45Y0lURLsesTPugdwFCkRq9IZSTrqJTRx+O1phnXL9aYQ/0YzPWqN8JU80iLku UlCywWxLxXsC4IAQ== From: "tip-bot2 for Qianli Zhao" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/core] timers: Mask invalid flags in do_init_timer() Cc: Qianli Zhao , Thomas Gleixner , x86 , LKML In-Reply-To: =?utf-8?q?=3C9d79a8aa4eb56713af7379f99f062dedabcde140=2E15973?= =?utf-8?q?26756=2Egit=2Ezhaoqianli=40xiaomi=2Ecom=3E?= References: =?utf-8?q?=3C9d79a8aa4eb56713af7379f99f062dedabcde140=2E159732?= =?utf-8?q?6756=2Egit=2Ezhaoqianli=40xiaomi=2Ecom=3E?= MIME-Version: 1.0 Message-ID: <160097843425.7002.2118619969908419648.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the timers/core branch of tip: Commit-ID: b952caf2d5ca898cc10d63be7722ae7a5daca696 Gitweb: https://git.kernel.org/tip/b952caf2d5ca898cc10d63be7722ae7a5daca696 Author: Qianli Zhao AuthorDate: Thu, 13 Aug 2020 23:03:14 +08:00 Committer: Thomas Gleixner CommitterDate: Thu, 24 Sep 2020 22:12:18 +02:00 timers: Mask invalid flags in do_init_timer() do_init_timer() accepts any combination of timer flags handed in by the caller without a sanity check, but only TIMER_DEFFERABLE, TIMER_PINNED and TIMER_IRQSAFE are valid. If the supplied flags have other bits set, this could result in malfunction. If bits are set in TIMER_CPUMASK the first timer usage could deference a cpu base which is outside the range of possible CPUs. If TIMER_MIGRATION is set, then the switch_timer_base() will live lock. Prevent that with a sanity check which warns when invalid flags are supplied and masks them out. [ tglx: Made it WARN_ON_ONCE() and added context to the changelog ] Signed-off-by: Qianli Zhao Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/r/9d79a8aa4eb56713af7379f99f062dedabcde140.1597326756.git.zhaoqianli@xiaomi.com --- include/linux/timer.h | 1 + kernel/time/timer.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/include/linux/timer.h b/include/linux/timer.h index 07910ae..d10bc7e 100644 --- a/include/linux/timer.h +++ b/include/linux/timer.h @@ -67,6 +67,7 @@ struct timer_list { #define TIMER_DEFERRABLE 0x00080000 #define TIMER_PINNED 0x00100000 #define TIMER_IRQSAFE 0x00200000 +#define TIMER_INIT_FLAGS (TIMER_DEFERRABLE | TIMER_PINNED | TIMER_IRQSAFE) #define TIMER_ARRAYSHIFT 22 #define TIMER_ARRAYMASK 0xFFC00000 diff --git a/kernel/time/timer.c b/kernel/time/timer.c index a16764b..25e048d 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -794,6 +794,8 @@ static void do_init_timer(struct timer_list *timer, { timer->entry.pprev = NULL; timer->function = func; + if (WARN_ON_ONCE(flags & ~TIMER_INIT_FLAGS)) + flags &= TIMER_INIT_FLAGS; timer->flags = flags | raw_smp_processor_id(); lockdep_init_map(&timer->lockdep_map, name, key, 0); }