Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3593ybp; Thu, 3 Oct 2019 09:22:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqz1zCk+FapeaAS1Ik/zd/eKAxTqbE1XJbDFP7GxD6k3n/bLk2Ih0Pu7ZKsrnNHVosPk4I2C X-Received: by 2002:a17:906:3108:: with SMTP id 8mr8424703ejx.11.1570119743433; Thu, 03 Oct 2019 09:22:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570119743; cv=none; d=google.com; s=arc-20160816; b=tbuaqQuHJrs4jOxj+xiAMTXOGTkHdRgfONgAGE2tr2ril+KqCDaxss/a/oP9ER/e++ 7z7kBpB+UjiuPh4/J9adHNy1KCwfJ31pVBf1rIdTAN2du+83DwvwjQfnoCdS3kRbZECf PXsndCLUbyUMlY1VVUwTxyJO91ncGgv+QQNLC2BNjKCFVafgCiqJtdhte4K7tpmhGfaZ eEMEW9uFsA6AabGQ5zwXBBTVgX2UBEsKSSXzS4tyaViXD/ZvhmK3SIsSWn4n5TRZWU3T fp5wXgAEwYsVqd9n/SGtcPumoCK/K00UHzo27fnVv4nlZuRE7BY3OZb6V7bRNonoTWGK VLyg== 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=jDE2+vBxDQZwiUTCxtdvF6fX6gczfNCCR7WYobqeJIc=; b=R5yh9G3nVmAViwl9fTzAxumXHkmlmREbP19+yylqMuDKg49feeHEZAajbe9eT2A32o AVmhEpwEsRbDj2yIW6eYkLezAqY1TbPJj2nbJnlQHKhncntmvoWTYDvrM2qLkEkmcg4J qIFooIOYd4tNow/2wFaAVtrB4wjX9EV3GZ1y9B2c91acdfhdaEBmtssHaGOCc8FIXmiy 5ahKpQiWd30EPnVRat97oEypT1qsixpKkyhBWGH7gcTmbxjQMans5tE4ajjWjcVnvsUu joTkxerJHrINa0r25Qoq7c+ac0AXb8Tj3R/CGsJKKjNlrCzVxVuK/1NJIJKcggfLdlOD fH8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1VYpndM3; 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 f57si1830357ede.78.2019.10.03.09.21.59; Thu, 03 Oct 2019 09:22:23 -0700 (PDT) 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=1VYpndM3; 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 S2388658AbfJCQSe (ORCPT + 99 others); Thu, 3 Oct 2019 12:18:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:45166 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389515AbfJCQSc (ORCPT ); Thu, 3 Oct 2019 12:18:32 -0400 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 D3AAA20865; Thu, 3 Oct 2019 16:18:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570119512; bh=audjmHFkn6owmybGafMOtOI0Qdga+AxlxVfZCPjyW74=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1VYpndM3kAmpGR/ef7swSeaYwClCsOor5sO/OEitwXVC3i6qn6MHWoFFI0DS91j2X 1rGQ7Xp36yGvUlILz5ggopxoAmHsrFjsGDAHWcG3LElkp9RlhBgF9hPcaqR7IEOxPM 47CC01yNWcy+St+9dRySdaAqvjP6/x8HD16ej79s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , Frederic Weisbecker , Sasha Levin Subject: [PATCH 4.19 092/211] posix-cpu-timers: Sanitize bogus WARNONS Date: Thu, 3 Oct 2019 17:52:38 +0200 Message-Id: <20191003154508.098114396@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154447.010950442@linuxfoundation.org> References: <20191003154447.010950442@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: Thomas Gleixner [ Upstream commit 692117c1f7a6770ed41dd8f277cd9fed1dfb16f1 ] Warning when p == NULL and then proceeding and dereferencing p does not make any sense as the kernel will crash with a NULL pointer dereference right away. Bailing out when p == NULL and returning an error code does not cure the underlying problem which caused p to be NULL. Though it might allow to do proper debugging. Same applies to the clock id check in set_process_cpu_timer(). Clean them up and make them return without trying to do further damage. Signed-off-by: Thomas Gleixner Reviewed-by: Frederic Weisbecker Link: https://lkml.kernel.org/r/20190819143801.846497772@linutronix.de Signed-off-by: Sasha Levin --- kernel/time/posix-cpu-timers.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c index 76801b9b481eb..d62d7ae5201c5 100644 --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -375,7 +375,8 @@ static int posix_cpu_timer_del(struct k_itimer *timer) struct sighand_struct *sighand; struct task_struct *p = timer->it.cpu.task; - WARN_ON_ONCE(p == NULL); + if (WARN_ON_ONCE(!p)) + return -EINVAL; /* * Protect against sighand release/switch in exit/exec and process/ @@ -580,7 +581,8 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags, u64 old_expires, new_expires, old_incr, val; int ret; - WARN_ON_ONCE(p == NULL); + if (WARN_ON_ONCE(!p)) + return -EINVAL; /* * Use the to_ktime conversion because that clamps the maximum @@ -716,10 +718,11 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags, static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec64 *itp) { - u64 now; struct task_struct *p = timer->it.cpu.task; + u64 now; - WARN_ON_ONCE(p == NULL); + if (WARN_ON_ONCE(!p)) + return; /* * Easy part: convert the reload time. @@ -1004,12 +1007,13 @@ static void check_process_timers(struct task_struct *tsk, */ static void posix_cpu_timer_rearm(struct k_itimer *timer) { + struct task_struct *p = timer->it.cpu.task; struct sighand_struct *sighand; unsigned long flags; - struct task_struct *p = timer->it.cpu.task; u64 now; - WARN_ON_ONCE(p == NULL); + if (WARN_ON_ONCE(!p)) + return; /* * Fetch the current sample and update the timer's expiry time. @@ -1206,7 +1210,9 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx, u64 now; int ret; - WARN_ON_ONCE(clock_idx == CPUCLOCK_SCHED); + if (WARN_ON_ONCE(clock_idx >= CPUCLOCK_SCHED)) + return; + ret = cpu_timer_sample_group(clock_idx, tsk, &now); if (oldval && ret != -EINVAL) { -- 2.20.1