Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp744775ybn; Tue, 24 Sep 2019 08:52:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqwZcYwUCvuFqeIknSy7yJhvenZHjwWJf9LZPznhWRZcpKP/pP25AjZel+vlht9UjxfCcPZU X-Received: by 2002:a17:906:1998:: with SMTP id g24mr3043968ejd.305.1569340326532; Tue, 24 Sep 2019 08:52:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569340326; cv=none; d=google.com; s=arc-20160816; b=x8yl3XKEoiDp/Jv2+iCEgkpiuAM4B0fd+Yym1kWLkE9XpqMhaiRN0ypGdAL7ehMKUw 6RfDPVyof5zEtXNYyBLcpJXq7Us86qCcx29sHtNDDJ5Sj32niL/aLVPBu0pb0RM29U34 DtO4aQXyXS85h6i5yY/6+e5v9SgIMZsnAOd1obkZj5aB8xdDjeB1lcWwkAt40CZ83t59 VY0LsjFK680l6mtu67CZ4UWhLX3CXdbfNZq3yMQDI9IRIKTmy3q754SAcobEBO6N8yEs djvcdS+B3LZTgZJRcKEPlgECbb/SHIsLr1zBOxfP444DchBDdbfei1hZZDqEbndFQjB4 sqDg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VA75tMCLpm9lnJ/WNIh3O2vtn6cD+RurE8ihwhHMqQY=; b=M6Pt2Hz7FMi8z7jGRpAOBbwpgoI1VjBX0TfU1dJEvzARFw487O2aKmh0rUhUeQFGVy miVB7DXM74cqF1qSIGM1YvvG+H2rm4fKYaC3rvLep1eyx/I09xogS6VWor+E8+59XAex O/ZM42Zc1zDpF5GsVasmZamc1Q0xI3m+vHTKLgkNiEeI+HYw/qa8vCpojqwHm8j9mJEZ 8gel2/5zLADj3A/vQBh9guQmGrbapAVz19tybdb+rVpAz0DwQtELBmo0DhL5pKnuvnn9 wPU9ouExXNIB9IZQ72ifGgE0YaqCBn14v9QDcnUyI2U/UzM8dhMX5SftlLYWXwMlUzBc A1NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zdVgccMq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l48si1449896edc.276.2019.09.24.08.51.42; Tue, 24 Sep 2019 08:52:06 -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=zdVgccMq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438984AbfIVTeq (ORCPT + 99 others); Sun, 22 Sep 2019 15:34:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:43448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390522AbfIVSrG (ORCPT ); Sun, 22 Sep 2019 14:47:06 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 798F621479; Sun, 22 Sep 2019 18:47:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569178025; bh=BMdLIydfr0XqiBTIBaO/y9dLc3t97LMQFjAyQ1K7uX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zdVgccMqhKpIDoF0W9+k7YNtIZf96eFjwYFmGkJVagskpsZ1ztepNMEbASFgUvBSa pKGeyW3k5oyf9TiQ8vgC0UeXIYfr/juLoy5DK/wftHXV1GRZ54sUrpY+6iPw5zRoU1 4Fv3G5KbOTC1kZV8xfcwRBDSjTlKOPyITdS8NFAg= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Thomas Gleixner , Frederic Weisbecker , Sasha Levin Subject: [PATCH AUTOSEL 5.3 109/203] posix-cpu-timers: Sanitize bogus WARNONS Date: Sun, 22 Sep 2019 14:42:15 -0400 Message-Id: <20190922184350.30563-109-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190922184350.30563-1-sashal@kernel.org> References: <20190922184350.30563-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 0a426f4e31251..5bbad147a90cf 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 @@ -715,10 +717,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. @@ -1000,12 +1003,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. @@ -1202,7 +1206,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