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 56F381A682F for ; Fri, 20 Mar 2026 02:20:59 +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=1773973260; cv=none; b=f7I1S3Z2xu2XlNwX6yjHZ+Z7J5NSuLlKRH+ctbgyVEtedtxJWYCBMS94wADTcJqpGWN6XVEdyzft/64MNP5QsBnGUjH9KL+PZAhJIGoyZi8yUa/b5SFpeYPYO+K1kkC1D7GaSEpY9E6ULQ4w11v+VoqAbIQqS9WOUhNi1WYW7Mg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773973260; c=relaxed/simple; bh=xAJjUybMuHbLOFmChOMJTLRIsZB5KZRzn/F7UNFvYEg=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=IdZtayJ69WNWR6+9iwHuslrRDzSQxIQxFtS5/APB5u9xWzjdESGzo1y7qDC96AUpw4BG3S9JrYGqD9fwTbu6Fgkfw/1lu0cxdO4sFH2wMVlDgS3HweCCsYX8jtwSIhEQzBvCwUPsn9FvQ+pj0ITdfImhkWCjMA0uPlOucym4uys= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=d2mM+j+z; 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="d2mM+j+z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B576C19424; Fri, 20 Mar 2026 02:20:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773973259; bh=xAJjUybMuHbLOFmChOMJTLRIsZB5KZRzn/F7UNFvYEg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=d2mM+j+zzlcpCG0BBs1yglDCOks/bnHv0Nl6pO+QsXX8MPxCuzZLkv6891EK6D0g+ IEFGvj7YMn2vYnSktFPyQw2A+7HHtG2xNen8NC9Caup7zYCvrntX9a6KGeOe4Cqdtd EI1aNy8RP1HHqP51y+Xt/hV/tQQ8UmVFwEef25JHPQkEdujqHrO41E8O5+BA1SRX9R c1YbJZA4NPeFsxRNvfah1BZfTVzWJTpZPzL4j4r7DzZli2lo0dQjf8x9t9pbRXrP1B lSZ/Uyp9pAgwSNnseUgtCYb8QL6hj2Z8MIEo0OVxoAmuoePuWs5V9Fv1vNg2nccHhk hOnFH4veGrfFQ== Date: Fri, 20 Mar 2026 11:20:55 +0900 From: Masami Hiramatsu (Google) To: Andy Shevchenko Cc: Petr Mladek , Steven Rostedt , Rasmus Villemoes , Sergey Senozhatsky , Andrew Morton , linux-kernel@vger.kernel.org Subject: Re: [PATCH] lib/vsprintf: Fix to check field_width and precision Message-Id: <20260320112055.ddac4b158bb84b2d2a76fe00@kernel.org> In-Reply-To: References: <177388001976.19951.3455192731084870216.stgit@devnote2> 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 Thu, 19 Mar 2026 09:11:21 +0200 Andy Shevchenko wrote: > On Thu, Mar 19, 2026 at 09:26:59AM +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. > > ... > > > 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, "field width %d too large", width)) { > > Also use logical split as below: > > if (WARN_ONCE(spec->field_width > FIELD_WIDTH_MAX || spec->field_width < -FIELD_WIDTH_MAX, > "field width %d too large", width)) { OK, let me update it. Thanks, > > > spec->field_width = clamp(width, -FIELD_WIDTH_MAX, FIELD_WIDTH_MAX); > > } > > } > > ... > > > 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); > > } > > -- > With Best Regards, > Andy Shevchenko > > -- Masami Hiramatsu (Google)