Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2397694rdd; Fri, 12 Jan 2024 08:14:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IHd34A6NzACoBXntnNRaoJqz79zx0xtOoMvk71cIatIxROW2Jove2cojYjkgmqHJUgEu8PK X-Received: by 2002:aa7:d658:0:b0:555:b528:c892 with SMTP id v24-20020aa7d658000000b00555b528c892mr854759edr.66.1705076054445; Fri, 12 Jan 2024 08:14:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705076054; cv=none; d=google.com; s=arc-20160816; b=blsTwgfYbpwnKL+7SfNCoA5QxuQUTOo5DrzvqPmgiNvddFybVfdJPiWNvtwX6s1E15 bs7vvxEl5Z4mbKr4nZrb+4q8ucM3fT6sAStyOIQKsmInGxOg/W9owKcLnbfFiNWENRCa f/Ij9+eDDY8mQyBf5JwyVcgbN3r2UkIWGs8X9jaBSz6sQ03KvXXpZjai/bfw8F0KaXjI /pHsuR9Y2U2wC7NyGmhBDsTbf/3dFRcA7cb4jHhHJcfmDxVDKfE8G34QTesG3tf+b1av aJLwF22sjmHyzeRTvDocuvGUiyLkDkIc1r+Pku8DO9l2g4FpqY9XuQvLciXNvDdRc37P pkxg== ARC-Message-Signature: i=1; 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=Ygxv8Ru5TbyzMKF/Xst0+SpbVCu6NSH7oSmorHjV188=; fh=I1oqcDrVPa5i6ZTCgWYqF8MwWop5e6Cl0AelMcglBcg=; b=Mbm5p8EvStPSsr4UhNkRSco2G6AjoAPyJrh3tlbIdtjLUj+csQFCLRkUHj3AHWqHbW fhET6NPCArRt3lQ0xL3jqzPOj8zzmPBXCYh0pn+S4BRrXksfqhVKU6EhehkNQ7Z8mb3A jD+pCNFfCGj2Z/EjNjHjUU8wtHxHJssRAvt4prml4X69H1sOzF5hlARKc0wuh4AVjpVk RCPn8mN+gRNo8PbdFH79Fl4YPBdPwVqwc2+z4E1BXJ1cTbJgBB/7S2hhoobrulrekcwL YMzyQ0t+ey8iKhOqSsGaYKWtIZKXi70VQZkQgN/tkR0miHVgc7Pyzf+blELtf0Sf7e5b MQBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0lePuOed; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-24848-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24848-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id f20-20020a056402069400b00553bc1bfbb9si1502186edy.381.2024.01.12.08.14.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 08:14:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24848-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0lePuOed; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-24848-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24848-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 354591F25521 for ; Fri, 12 Jan 2024 16:14:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A84A473173; Fri, 12 Jan 2024 16:14:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="0lePuOed"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ZaIzkr80" 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 972AB73169 for ; Fri, 12 Jan 2024 16:14:03 +0000 (UTC) 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=1705076041; 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=Ygxv8Ru5TbyzMKF/Xst0+SpbVCu6NSH7oSmorHjV188=; b=0lePuOedlNKaxSu4plGB1eRHEWwHwPzdyzLPXhnW0E3QG+Glks7Asnooot636ljJu18MEj 6PCwyt1dKCdfAtZtjTTzlxcFScaAxSQFuUbb0HCFOGXUmpXqVI0Do8/qI2AiYoW55ejDFP FG75gP+pzIwokb2eJbli4zXrgdiMmTT3apROw9pjgoUjUSLL72QJKsA0w9ZuwYsRYbEKEy 15VXSDieIo/8SQUljwmvdzNnBOTUFGTlkE5LcLGhSAvCvVlnPsAGuJOxV5dN3iOzb4NHRl +4HUbEmB0izdZlIl2ojC9W+p90IkEGgP/vh4sYysT6+61KI71t6mtnY8usTFpw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1705076041; 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=Ygxv8Ru5TbyzMKF/Xst0+SpbVCu6NSH7oSmorHjV188=; b=ZaIzkr80DeMtyLRbqsZ3p6hgeUHLsHNZpHOdAfwcl0WlOIHhBenay5IA1D9gMDHIgNsuyM oyKr0u8wD+ntoOCg== To: Simone Weiss Cc: simone.weiss@elektrobit.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] Fix UBSAN warning for subtracting ktime_t In-Reply-To: <20231219124434.870613-1-simone.weiss@elektrobit.com> References: <20231219124434.870613-1-simone.weiss@elektrobit.com> Date: Fri, 12 Jan 2024 17:14:00 +0100 Message-ID: <878r4uil6f.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 Tue, Dec 19 2023 at 13:44, Simone Weiss wrote: > UBSAN: Undefined behaviour in kernel/time/hrtimer.c:612:10 > signed integer overflow: > 9223372036854775807 - -51224496 cannot be represented in type > 'long long int' Some explanation about the context and why the offset is < 0 would be helpful. > +/* > + * Sub two ktime values and do a safety check for overflow: > + */ > +ktime_t ktime_sub_safe(const ktime_t lhs, const ktime_t rhs) > +{ > + ktime_t res = ktime_sub_unsafe(lhs, rhs); > + > + if (lhs > 0 && rhs < 0 && res < 0) > + res = ktime_set(KTIME_SEC_MAX, 0); > + else if (lhs < 0 && rhs > 0 && res > 0) > + res = ktime_set(-KTIME_SEC_MAX, 0); Looking at the use cases, the lhs < 0 case would be a bug because the expiry values are strictly >= 0. > + > + return res; > +} > +EXPORT_SYMBOL_GPL(ktime_sub_safe); That export is needed because? The only usage is in this file so this can be static, no? Thanks, tglx