From patchwork Wed Jan 17 22:47:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 1887648 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=gandalf.ozlabs.org; envelope-from=srs0=yxps=i3=vger.kernel.org=linux-ext4+bounces-841-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TFgzg0qQhz1yPv for ; Thu, 18 Jan 2024 09:49:18 +1100 (AEDT) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4TFgzf15M1z4x2P for ; Thu, 18 Jan 2024 09:49:18 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4TFgzf0lmfz4xCp; Thu, 18 Jan 2024 09:49:18 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=fail (p=none dis=none) header.from=ACULAB.COM Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-ext4+bounces-841-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4TFgzf0dpJz4x2P for ; Thu, 18 Jan 2024 09:49:18 +1100 (AEDT) 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 6084FB214DE for ; Wed, 17 Jan 2024 22:49:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 43C3C22F16; Wed, 17 Jan 2024 22:49:05 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) (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 5D7611E87E for ; Wed, 17 Jan 2024 22:49:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.58.86.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705531745; cv=none; b=q53PEkhF+FLl8pr2D51x2CcVEVvHNWzku/XycjolvAlZVyaZua39lYCvXddjdNLJnSIObd8WnMuWubG1/W9oohQsNdYMPamZdDx4e7oBJCKWSgi0yezm6gKhBToglOYYow8gmbpJ5I4GuTMuZUols9Se6aPQEFaEJjfTP54LNiA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705531745; c=relaxed/simple; bh=BUcf8xHpEIiBvl8cLb2c21ckzGB5onz3r6wFRqc2vIk=; h=Received:X-MC-Unique:Received:Received:From:To:CC:Subject: Thread-Topic:Thread-Index:Date:Message-ID:Accept-Language: X-MS-Has-Attach:X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader:x-originating-ip: MIME-Version:X-Mimecast-Spam-Score:X-Mimecast-Originator: Content-Language:Content-Type:Content-Transfer-Encoding; b=kcRdI31gWFoRwu+C2o+mGAfozr1okDQN7ex16UZH5P/6oya3wFnpx5gtTlc68MlYXaQLA5j3xaS0PiHYInIC3DePz8Dt/1GntywqunOX5ZF9nENVwVIlgWZqx5Nrn7lyY+5ahcKtb1GFW+V6sJOBoCz0VUaIe2O6r9vrtFkeKwQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM; spf=pass smtp.mailfrom=aculab.com; arc=none smtp.client-ip=185.58.86.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aculab.com Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-143-tHS3zxe8MH66648R1lNVPg-1; Wed, 17 Jan 2024 22:47:32 +0000 X-MC-Unique: tHS3zxe8MH66648R1lNVPg-1 Received: from AcuMS.Aculab.com (10.202.163.6) by AcuMS.aculab.com (10.202.163.6) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Wed, 17 Jan 2024 22:47:16 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Wed, 17 Jan 2024 22:47:16 +0000 From: David Laight To: "linux-kernel@vger.kernel.org" , "linux-ext4@vger.kernel.org" , Arnd Bergmann CC: "Theodore Y. Ts'o" , "'adilger.kernel@dilger.ca'" Subject: Subject: [PATCH next] ext4: super: Use clamp() instead of clamp_val() to bound timestamps Thread-Topic: Subject: [PATCH next] ext4: super: Use clamp() instead of clamp_val() to bound timestamps Thread-Index: AdpJlv7FNtWwV0cSQNCCM5QNS6v7lg== Date: Wed, 17 Jan 2024 22:47:16 +0000 Message-ID: <364a2f251cab4b2fbd43c661d51fcdd5@AcuMS.aculab.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Commit 6a0678a79bb3a extended the superblock timestamps to 40 bits. The time64_t (signed 64bit) was bounded using: now = clamp_val(now, 0, (1ull << 40) - 1); which is equivalent to: now = clamp(now, (typeof(now))0, (typeof(now))((1ull << 40) - 1)); However clamp_val() is an 'accident waiting to happen' because it is very easy to specify bounds that get masked by the cast. The current clamp() only requires the three values to have the same signedness - not the same types. So changing the upper limit to a signed value allows clamp() be used. This is the only place in the kernel I build where replacing clamp_val() with clamp() generates a compile-time error. This is a similar 'problem' to code like: unsigned int val = ... u8 bounded = min_t(u8, val, 255); which is surprisingly common and has been a real bug. Signed-off-by: David Laight --- fs/ext4/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 0980845c8b8f..714d51a1667b 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -425,7 +425,7 @@ void ext4_itable_unused_set(struct super_block *sb, static void __ext4_update_tstamp(__le32 *lo, __u8 *hi, time64_t now) { - now = clamp_val(now, 0, (1ull << 40) - 1); + now = clamp(now, 0, (1ll << 40) - 1); *lo = cpu_to_le32(lower_32_bits(now)); *hi = upper_32_bits(now);