Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp494786lqb; Fri, 24 May 2024 05:09:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXG0eS6YaoRuEuA4tJpDkFwHtynYwujRgwrZb9HvU59hACM0oSC4o6yZtfV+VmsW+1wludSDS6vATvIwvd9kKmz1lmCm/Tg8ShNf2+5Bw== X-Google-Smtp-Source: AGHT+IEwf8B8Y85wLHwfKgAOmqL1e2tlxfcfiWZAFVG9ey4XWDRh9UFhr4Rkbkv/1IxxMuHBzn5j X-Received: by 2002:a50:998a:0:b0:56e:3293:3777 with SMTP id 4fb4d7f45d1cf-57851955618mr1899979a12.17.1716552591390; Fri, 24 May 2024 05:09:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716552591; cv=pass; d=google.com; s=arc-20160816; b=Mz07UkR+ifVNnS7BvYvKSU8awsmJR99VbCdFc7Rfn7GkBK72GJRQteHHGdzDHSkgJ+ ZZ233qnxoyCRG8ISqNmbIVPKbQ0a9SlJ+Tk2pyXnvi0hsFrhtwxfP0xKAzo43jh/Rwua vKqYrYlHVZegxfmsbHhm4PiXhOPlxBDWNa0jkVK+Y2QNDnfySUq2Jt0QycNKY0bz6Rsv WuDgq/k4C8UrbXNQHWpfBNfYIk5p4hLVtImXTAUn7iNvmzNJGySi8BhKOO/k8Cal0lUj XaSYSHbY8/RTMguV3dC6PxasELdiRgClmDWJMzbeyAQwS8i6XN9Fsn5EDa1cfxzR9EW3 7bXg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:references:in-reply-to:subject:cc:to:dkim-signature :dkim-signature:from; bh=KwrJkb5UWtVpW+6uKKTmNSXBikkf8k2POmcqYvLF5LE=; fh=kh1BEgL3RhIDbDvnY7/63dOFmL4tiYD8Um4YfBF6jjc=; b=FQl0lnTJ/ywP7jmza7kel3+pwa+skjdWFABpQSbAYEzVoCMC2H/ox/c34wFqq2KG1s yJSzgiWGTh8Vxlf7WARcPTxiEIdwP6oVQ19UEsxZ+P975T7suWVUK6VsOpTTJVeUx88n qmKDnXUz9MGCc8IP+Set3MWFDTjLgLcbn9y/R5RVWVtEOHxhoKl996Wpo6R2qycLdvuz L/nbnVPNcxHJprJR9AVs/Z7aOoUZv5SBG6UZ6y6hkleRyudmBJFipN+fUjX9E6TJ0KC+ xmBF5/3k86ZHwg8QXA91wzdTXOSczO87uM5/9Vmsynwkb7v8z0gVUYSMMMGrVV4LkAYq kJQg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=pW4oKXsd; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-188663-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188663-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5785245fa59si817986a12.319.2024.05.24.05.09.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 05:09:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-188663-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=pW4oKXsd; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-188663-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188663-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 24ADB1F22607 for ; Fri, 24 May 2024 12:09:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 982578626A; Fri, 24 May 2024 12:09:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="pW4oKXsd"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="FZDiGBBf" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CDA18563E; Fri, 24 May 2024 12:09:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716552583; cv=none; b=T/zNLWz/OVt+1C0FuEMga/Tu+smKSGcysiBF0RYDvLHtN3cVOZnjYecmWFqYq7AiI0JV9itDWDy0ywt8uUKAU/fQMvbYmtfUiRK62ag0YTAloeoqYupBz2eOep5cf31LITmIddF6PRVChcSOC09rVXNxnLzb94bx8s7P+sGr9lU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716552583; c=relaxed/simple; bh=wJXQkk1V3FlJQgr1pPSLFK/VZCsoXjvfYpl1+qjKKjs=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=GYzx/avEaNBV3IAKML9FZCUnfiH2B0Vo6dbwz6awPBlnEr+8is5roOMJPb1OJ22+LIHuSENANArF6nMd5NDxsQPJQtKKgKpETBh4oJnUhrtgbV5fgRh7KG0+UeXyredUahRsxS9YsPyv06nlFj8j0h1Y1uYl59t25aVtlH8LggA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=pW4oKXsd; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=FZDiGBBf; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1716552580; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=KwrJkb5UWtVpW+6uKKTmNSXBikkf8k2POmcqYvLF5LE=; b=pW4oKXsdeuaZgoTWdrml6XjbqmgrqdpmmH2MubZjxWL63MLmcW1vw/G93JHPUpDoMCNkp2 rDcIIO1iMWPq2WKwZYxDZqoHUoa6Tfdx5j6AYl5dJO5K3r6FY4SmlUipcidw1JKDDd6nHt lYwtB4HZArKPdYOLOT19nqFoTIILt4TMUgj0nNpoJ72DZGjd6GVuQTomHBkP4g08KbmK18 3QolkNFpiXR1TwkRcemfFGMaza53vqLmkEImRuPOE3/zw5KOceuW/obPiKoEWvKpVEM915 LvUH3E6mMMseBUEWN/vz0K06/ek8I1/oqHfwQyNzbwCp9kOefHkHTGxXs8f4dQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1716552580; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=KwrJkb5UWtVpW+6uKKTmNSXBikkf8k2POmcqYvLF5LE=; b=FZDiGBBfBuVXX2DRLl4ddYpgChHlXu3v5tNdnqJknphBtYWA+QP66aasNIxadcqqphj9sQ YbxFrVRYokfkWiDg== To: Justin Stitt , John Stultz , Stephen Boyd , Nathan Chancellor , Bill Wendling , Nick Desaulniers Cc: linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org, Justin Stitt , Miroslav Lichvar Subject: Re: [PATCH v2] ntp: remove accidental integer wrap-around In-Reply-To: <20240517-b4-sio-ntp-usec-v2-1-d539180f2b79@google.com> References: <20240517-b4-sio-ntp-usec-v2-1-d539180f2b79@google.com> Date: Fri, 24 May 2024 14:09:39 +0200 Message-ID: <87ed9re7i4.ffs@tglx> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On Fri, May 17 2024 at 20:22, Justin Stitt wrote: > time_maxerror is unconditionally incremented and the result is checked > against NTP_PHASE_LIMIT, but the increment itself can overflow, > resulting in wrap-around to negative space. > > The user can supply some crazy values which is causing the overflow. Add > an extra validation step checking that maxerror is reasonable. The user can supply any value which can cause an overflow as the input is unchecked. Add ... Hmm? > diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c > index b58dffc58a8f..321f251c02aa 100644 > --- a/kernel/time/timekeeping.c > +++ b/kernel/time/timekeeping.c > @@ -2388,6 +2388,11 @@ static int timekeeping_validate_timex(const struct __kernel_timex *txc) > } > } > > + if (txc->modes & ADJ_MAXERROR) { > + if (txc->maxerror < 0 || txc->maxerror > NTP_PHASE_LIMIT) > + return -EINVAL; > + } I dug into history to find a Fixes tag. That unearthed something interesting. Exactly this check used to be there until commit eea83d896e31 ("ntp: NTP4 user space bits update") which landed in 2.6.30. The change log says: "If some values for adjtimex() are outside the acceptable range, they are now simply normalized instead of letting the syscall fail." The problem with that commit is that it did not do any normalization at all and just relied on the actual time_maxerror handling in second_overflow(), which is both insufficient and also prone to that overflow issue. So instead of turning the clock back, we might be better off to actually put the normalization in place at the assignment: time_maxerror = min(max(0, txc->maxerror), NTP_PHASE_LIMIT); or something like that. Miroslav: Any opinion on that? Thanks, tglx