From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5EEAD36C5BB for ; Sat, 21 Mar 2026 13:07:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774098437; cv=none; b=IGyEKmim6w6a5PRi+1SoaThctIB7A/EaGF5pz6RfcS564pi4Zme3q7aTB3D8FyIEG8BIFed+676r/R0KhvLCx1LgHE8vfQxkxgpEb4mEZPrADXdjmeaPmTru1QF7Vzfy6fSfLQjE1o6tuDJic+jOPA0yyPnXsv3lE68gz0d5e+k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774098437; c=relaxed/simple; bh=ZA2XqmYAbm7EjgNhyaJ9Vk1Knfx02cIAtMXaze/0ntE=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=H74vqXdcRBHHqyzksnDRVGc98x/CV7obql4jZL+Sh6f2mrMWdhbPeHoNBsc8NQov9zWRvnxg8vDXgtZGsm2d0O3asGmSImMqGyrZNXGcgPq4D1VsEZ7hpyJu3GHCM2aPGKY7ZCVUhhBibBW1s5fmpbwOylMFOZIIT9ERM1+aSTc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Awgb7xjT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Awgb7xjT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0196EC19421; Sat, 21 Mar 2026 13:07:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774098437; bh=ZA2XqmYAbm7EjgNhyaJ9Vk1Knfx02cIAtMXaze/0ntE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Awgb7xjTU5kNKTfocWJGat/8rdN3c/vvuK7DbpIBKO63ako4v9BKp1B4UYLd6yw6v JOmNnwfNjtgbvQtlmAE2fgFmncIERl3RS2P+zhikiSaNVTcK8iFiS58rfnCMvEk7p8 tKdcPLT85lHuaoYyn2HNvrJ6R5f+4h0H1Og2DDVyhKDxaq3ShCdcTk0RUzWVNwPK1t XqOrhwLoCs8l2+fphBusb/4+Tko7IRWXVcYA+Q49Fs++lEIJ/2NUDtT9qMt+lkNqyJ 0fXtk3WB18LuTmG88RGiiVogW6zYcuBInnNqO3/pBxCllbKik659tc99EsYv62xawB BMupXkhHWSm3g== Date: Sat, 21 Mar 2026 22:07:12 +0900 From: Masami Hiramatsu (Google) To: David Laight Cc: Petr Mladek , Steven Rostedt , Andy Shevchenko , Rasmus Villemoes , Sergey Senozhatsky , Andrew Morton , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/2] lib/vsprintf: Fix to check field_width and precision Message-Id: <20260321220712.2845dfa860a03bbd837a8fe3@kernel.org> In-Reply-To: <20260320094858.36979c73@pumpkin> References: <177397887883.33018.9867883986177366222.stgit@devnote2> <177397888866.33018.11400875989661138560.stgit@devnote2> <20260320094858.36979c73@pumpkin> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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 Fri, 20 Mar 2026 09:48:58 +0000 David Laight wrote: > On Fri, 20 Mar 2026 12:54:48 +0900 > "Masami Hiramatsu (Google)" wrote: > > > From: Masami Hiramatsu (Google) > > > > 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. > > > > Fixes: 938df695e98d ("vsprintf: associate the format state with the format pointer") > > Reported-by: David Laight > > Closes: https://lore.kernel.org/all/20260318151250.40fef0ab@pumpkin/ > > Signed-off-by: Masami Hiramatsu (Google) > > --- > > Changes in v2: > > - Fix to use logical split. > > --- > > lib/vsprintf.c | 6 ++++-- > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > > index 800b8ac49f53..32a164e2adf4 100644 > > --- a/lib/vsprintf.c > > +++ b/lib/vsprintf.c > > @@ -2803,7 +2803,8 @@ 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)) { > > + if (WARN_ONCE(spec->field_width > FIELD_WIDTH_MAX || spec->field_width < -FIELD_WIDTH_MAX, > > Check and update width before the assignment to spec->field_width. > > David Indeed. I'll do the same for precision. Thanks, > > > + "field width %d too large", width)) { > > spec->field_width = clamp(width, -FIELD_WIDTH_MAX, FIELD_WIDTH_MAX); > > } > > } > > @@ -2812,7 +2813,8 @@ static void > > set_precision(struct printf_spec *spec, int prec) > > { > > spec->precision = prec; > > - if (WARN_ONCE(spec->precision != prec, "precision %d too large", prec)) { > > + if (WARN_ONCE(spec->precision > PRECISION_MAX || spec->precision < 0, > > + "precision %d too large", prec)) { > > spec->precision = clamp(prec, 0, PRECISION_MAX); > > } > > } > > > -- Masami Hiramatsu (Google)