From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEA033B7744 for ; Mon, 23 Mar 2026 13:59:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774274350; cv=none; b=AKqVRuAln9Y1K30+jvUYmbjf0UGFjSq/sqmzvIz45CSdbFFgFceUHBDL5vn4gtUpNV3kpmdvhYxfA6P0N7esGZcOh2Pu02tUVUSgy681FIg3Z3H7E7imU4CGuSOsoeagWiAs1hpnl+3PL6iAbsLBsmTJnurmm2/NVIwz3igBBP4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774274350; c=relaxed/simple; bh=ajiwTr1R0+2jDyK4MmoHBo/egAc/ywfb4QxLvST8VsE=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dLTFyjrtMfXLXcG/S91ESBz2Bny8ErtGWnaMXCdE0RIZQOCEXdhG0vPXYnfcj8e5KJGTFThi4ZyukiLS+jlnQyHx+MdF01FAfN5wdxddlvgmmoLRUSH09KpwNE+oikArZi7UY8L7KY5tZBV8ajUzynCxvIrpFxSj/s8ydPJ8M+o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZTtf5dJ6; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZTtf5dJ6" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-48540d21f7dso33616995e9.0 for ; Mon, 23 Mar 2026 06:59:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774274347; x=1774879147; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=dSKSCpnTtQgs7V1ImtU/JUWR4KM5gKwJed5lZZDlYWc=; b=ZTtf5dJ6uT7y88KpSpk4PfI2dyeWVWrc4GoKlIURUUuKj904RIyKBaTNk1Xdd8erkR J5t258I7lw7qGhrHj0a360nLPswOoYnzA+/F5tww2g9an+dEhIluhZfk/kdy41212y7m /WWHX2hcaJmWcxq291tZ9gRHLWQOmS9ACb+oIZBv47VkwnILeyosC/LmF6mMKxGNdcBE /4Vl5zUKJzeBkQRZB1S1pRuPjYX0nlrdP9hPQwtJKIiSvAGgLFEQl5WLneRNn7MGZaNY yNXXU5tT0e22Nb3wskpRvya1M+sfCIx/tXuyHpknFdJ8hf1jYSbMCFc7pkRAdaIgJjkI In8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774274347; x=1774879147; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=dSKSCpnTtQgs7V1ImtU/JUWR4KM5gKwJed5lZZDlYWc=; b=O3oBg04gV6d2ALAqHYUwHXHlNyRdJTOV7+E8203nz5jz6wxW6R7IbLIsbP7HOkBQou fdWtlO85uODu4D0LjT2783TeDufIvLpzZHi3ErNrWF4qzWBtSRfzoLCJ1gdrssYtPOlz Y59f5UYsD0dYBrOc0CC4Mul0UllNuxN7T1AI62CiZWMfzc9ZqW64B4uHVAAOaD76bkkV 40jnOdiPKBRqwsmxtoUS9Nccx4vQu4diwkYIoWuKgEJKLm3VjtPS4yooLZ6LK1iD1DVf bCSVNqzdRicH39s1j3eJkKBuZ3iEDbMDqDZ3enf0Xzo4eh2m6QLuj5/ghyaMryoBpkIb J1oQ== X-Forwarded-Encrypted: i=1; AJvYcCXpEGhmQEGx/QVAKA5zXUIm0jPZ/6Ll/WkOqrJzFFsHKW1f+fyERlgAi+EJb7EOzw++X5r6p9YI8pnAEH4=@vger.kernel.org X-Gm-Message-State: AOJu0YxeMeSYnqdARL39/rbNcrTZFV9I2QMo4f2vJb03Dcz3khAcoRdo GhibJgn7/4EdH6/4dhdV7cTBOZd5EwNbKtNBWfKxPjrqHFjImb0K0j3c X-Gm-Gg: ATEYQzynqwBU8pp5vmPJ0eGdmfM0whzHUBOF6Rg+un39vEV+aFvICXwMoNMHf0+BmxG MVfyu0JrZkP/eePT9UiNfaur1Ny/OmSmtLlZ6dQZeRqhjNSZw3oyq+waL9xgjSXxIFPIGUgWWMu FIOLMBal+mHkhVuHEDOTRGxb3+cKsvUBIGKlzi39G3ORmP3TLiesHrdcSc/NOyqCVjqe2HfMkUZ Xe7BB0VxkyIlswUm2PqHKerZ2Y0MALohiK3iD2HmTR7HL9G5pPQ1uRQPzCJ50zemlcwtPDeTNoJ yRyq43VzCKefU9sm0m0D7T1MXm5IVy7rVuKc2kIF1xOWVA2YmUcsuyqBfAmXV5FcuxAlMt64a84 OKeAFTCFSdEw2YskVp8g6nJLd1n+MxVL8D38QkNKV1NyL57RGZmgRJBg/k/wkHkxel5k2KwFmGI mktJxFDpBZQXq5OhBLNHMPGDaFzkont4gp9oz9IyBx5K+UAxYdhXemtVg8Y5qM1Mnk X-Received: by 2002:a05:600c:3b23:b0:486:fdc6:1c0d with SMTP id 5b1f17b1804b1-486ff02da9emr182162345e9.22.1774274346934; Mon, 23 Mar 2026 06:59:06 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48700377b71sm116459515e9.0.2026.03.23.06.59.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 06:59:06 -0700 (PDT) Date: Mon, 23 Mar 2026 13:59:05 +0000 From: David Laight To: Andy Shevchenko Cc: "Masami Hiramatsu (Google)" , Petr Mladek , Steven Rostedt , Rasmus Villemoes , Sergey Senozhatsky , Andrew Morton , linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 1/2] lib/vsprintf: Fix to check field_width and precision Message-ID: <20260323135905.5272127b@pumpkin> In-Reply-To: References: <177410406326.38798.16853803119128725972.stgit@devnote2> <177410407207.38798.2345647618225402693.stgit@devnote2> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 23 Mar 2026 15:27:31 +0200 Andy Shevchenko wrote: > On Sat, Mar 21, 2026 at 11:41:12PM +0900, Masami Hiramatsu (Google) wrote: > > > Check the field_width and presition correctly. Previously it depends > > on the bitfield conversion from int to check out-of-range error. > > However, commit 938df695e98d ("vsprintf: associate the format state > > with the format pointer") changed those fields to int. > > We need to check the out-of-range correctly without bitfield > > conversion. > > ... > > > static void > > set_field_width(struct printf_spec *spec, int width) > > { > > - spec->field_width = width; > > - if (WARN_ONCE(spec->field_width != width, "field width %d too large", width)) { > > - spec->field_width = clamp(width, -FIELD_WIDTH_MAX, FIELD_WIDTH_MAX); > > + if (WARN_ONCE(width > FIELD_WIDTH_MAX || width < -FIELD_WIDTH_MAX, > > + "field width %d too large", width)) { > > + width = clamp(width, -FIELD_WIDTH_MAX, FIELD_WIDTH_MAX); > > } > > + spec->field_width = width; > > } > > > > static void > > set_precision(struct printf_spec *spec, int prec) > > { > > - spec->precision = prec; > > - if (WARN_ONCE(spec->precision != prec, "precision %d too large", prec)) { > > - spec->precision = clamp(prec, 0, PRECISION_MAX); > > + if (WARN_ONCE(prec > PRECISION_MAX || prec < 0, > > + "precision %d too large", prec)) { > > + prec = clamp(prec, 0, PRECISION_MAX); > > } > > + spec->precision = prec; > > } > > Looking at this, perhaps > > #define clamp_WARN_*(...) > ... When I looked at this I did wonder whether the compiler would manage to only do the comparisons once. Even if it doesn't the separate WARN is more readable. Or maybe: spec->field_width = clamp(width, -FIELD_WIDTH_MAX, FIELD_WIDTH_MAX); WARN_ON(spec->field_width != width, "field width %d too large", width); I'd be more worried about the bloat and system panic for all the systems with panic_on_warn set (the default for many distos). (And, like panic_on_oops, it doesn't give time for the error to get into the system logs.) I've also just fixed nolibc's handling of %*.*s (which is in 'next' since I only wrote it recently), the above is actually broken. Negative 'precision' (all values) are fine, they just request the default. So the patch needs a big fat NACK... David > > Potential users besides these two: > > arch/powerpc/platforms/pseries/papr-sysparm.c-39- > drivers/gpu/drm/drm_color_mgmt.c-142- > drivers/gpu/drm/i915/display/intel_backlight.c-48- > drivers/media/i2c/vgxy61.c-952- >