From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sender-of-o57.zoho.eu (sender-of-o57.zoho.eu [136.143.169.57]) (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 56E4F3E4C6C for ; Tue, 31 Mar 2026 16:13:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.169.57 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774973609; cv=pass; b=nPgr7b4DBL7foEYgshDnJ25hHdzf0hrtdvJuHOdeiAOBNJP3ftSsKNYjQ9ZPXyyw6By94b4bN3BEBF6mTFkh2q+XgptYInYTNc4bKdZlmJqQgsaHzrksrMxw5EuE4ApC4iyad19lL8E10DvxemXIw6ifFTFNd0cpKFqvyI8MGbs= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774973609; c=relaxed/simple; bh=HDrgjlQnuBb4ec/lpJkHpp3THur+NnFbMWrxqNqpixY=; h=Date:From:To:Cc:Message-ID:In-Reply-To:References:Subject: MIME-Version:Content-Type; b=uKF47jh+NMz9svEPb/qCzhvXgQTJvdYGtIIoZaf/yQHIqdj3dqsY0UXtWj+e4kr8CC2UJXxMIJoBmZWosi2To1mVhYBcz10W69VrpGzjMvEGJOKOcgAfXXEip58YKiHqLqHNVX61rQXWMMw/FmY1TGwL5hwxD3SK+vf9h8xfOm0= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org; spf=pass smtp.mailfrom=objecting.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b=m2KyluQn; arc=pass smtp.client-ip=136.143.169.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=objecting.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b="m2KyluQn" ARC-Seal: i=1; a=rsa-sha256; t=1774973594; cv=none; d=zohomail.eu; s=zohoarc; b=SzebEPgQQESzTZDR2nyytPMkPV4KKLU3zc2vH5jSaJmsXnj5QP2JfZDZ0xLp86t7dGyzhaKn5F8sPGYnvbKnIUSU7mCprTP2Wkfp6ehmgAv9H6QOUwg0IyBEhzfejjy36lZg5jB7xblcRPIfZkcMQZlMlsK2UE9cTMMHFbCLYXg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1774973594; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=HDrgjlQnuBb4ec/lpJkHpp3THur+NnFbMWrxqNqpixY=; b=TSKk8RUfaWmVwxxzzlm1AbSNGiG62KjFEzg8Ptu7bZZSC9v7otg5tlJ/TAB4aQFvcbOhfJLjPHozFzLHrHebcssIPdenNT0jNdEtHpw+MmbEaKKsPCPhUW9J596H1J80Ekje7H1JYLTBEKZ53MVCBdKasoakaJ/OECGGKxdWXP0= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=objecting.org; spf=pass smtp.mailfrom=objecting@objecting.org; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1774973594; s=zmail; d=objecting.org; i=objecting@objecting.org; h=Date:Date:From:From:To:To:Cc:Cc:Message-ID:In-Reply-To:References:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=HDrgjlQnuBb4ec/lpJkHpp3THur+NnFbMWrxqNqpixY=; b=m2KyluQnn/JE3YMXOr2rOFCRyrUBY7LnZloBSsKCRjJUQmypEtNZxrZ5h2HRFizk R2QjqLvgJDWYgxQ/EURqVUZIvrpJLWLhrOYfm3GFbTakOhJbSxQdWQ+E5zTBMvYwEA6 PljEmqL6EFM39Ux9K89ZWyVLVNxpqAto09xke64g= Received: from mail.zoho.com by mx.zoho.eu with SMTP id 1774973594263165.42928473999098; Tue, 31 Mar 2026 18:13:14 +0200 (CEST) Received: from mail.zoho.eu by mx.zoho.eu with SMTP id 1774973593277409.09359600261575; Tue, 31 Mar 2026 18:13:13 +0200 (CEST) Date: Tue, 31 Mar 2026 17:13:13 +0100 From: Josh Law To: Cc: , , , , , , Message-ID: <19d44aba6bc.594b8289101455.350028308144098434@objecting.org> In-Reply-To: References: <20260324224940.50508-1-objecting@objecting.org> <20260324224940.50508-4-objecting@objecting.org> <20260331163522.74467342@pumpkin> Subject: Re: [PATCH 3/4] lib/vsprintf: use int for field_width in vsscanf() 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="UTF-8" Content-Transfer-Encoding: quoted-printable Importance: Normal User-Agent: Zoho Mail X-Mailer: Zoho Mail ---- On Tue, 31 Mar 2026 17:12:18 +0100 pmladek@suse.com wrote ---- > On Tue 2026-03-31 16:35:22, David Laight wrote: > > On Tue, 31 Mar 2026 16:31:50 +0200 > > Petr Mladek wrote: > > > > > On Wed 2026-03-25 14:00:17, Andy Shevchenko wrote: > > > > On Tue, Mar 24, 2026 at 10:49:39PM +0000, Josh Law wrote: > > > > > vsscanf() declares field_width as s16 but assigns it from skip_at= oi() > > > > > which returns int. Values above 32767 silently truncate to negati= ve, > > > > > causing vsscanf() to abort all remaining parsing. This is inconsi= stent > > > > > with struct printf_spec which uses int for field_width. > > > > > > > > Is the field_width an acceptable integer range by the specification= s? > > > > > > I am not sure what is allowed by specification. Anyway, the code is > > > not ready for a bigger values, for example: > > > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0case 's': > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0{ > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0char *s =3D (char *)va_arg(args, char *); > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0if (field_width =3D=3D -1) > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0field_width =3D SHRT_MAX; > > > > > > clearly expects signed short int range. > > > > > > I wonder if it might even open some backdoor. The code matching > > > as sequence of characters expects a defined field width, see > > > > > > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0case '[': > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0{ > > > [...] > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0/* field width is required */ > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0if (field_width =3D=3D -1) > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0return num; > > > > > > The current code limits valid field width values to positive ones, > > I meant this code: > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0/* get field width */ > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0field_width =3D -1; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if (isdigit(*fmt)) { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0f= ield_width =3D skip_atoi(&fmt); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0i= f (field_width <=3D 0) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0break; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0} > > If we change the type of the local variable then the above check will > suddenly accept fied_width <=3D INT_MAX instead of SHRT_MAX. > > As a result, The above mentioned "case '[':" handling will suddely > allow to iternate over INT_MAX long string instead of SHRT_MAX. > > I doubt that there is any kernel code which would be affected > by this. But I do not want to risk it. > > > > aka SHRT_MAX which is clearly much lover than INT_MAX. And it might > > > prevent some out of bound access. > > > > Best Regards, > > > Petr > > > > > > > > > > Notwithstanding what the code actually does there is no point defining = a > > local variable as a 'short' unless you really want arithmetic to wrap > > at 16 bits. > > All it does is force the compiler to keep adding code to fix the sign > > extension to 32 bits. > > Look at the object for anything other than x86 (or m68k). > > If you think that it is important enough, feel free to send > a patch. > > I not taking this patch from Josh Law, definitely! > > Best Regards, > Petr > > PS: Note that Josh Law seems to be an AI virtual person, see > https://lore.kernel.org/all/cbd0aafa-bd45-4f4d-a2dd-440473657dba@lucifer.= local/[https://lore.kernel.org/all/cbd0aafa-bd45-4f4d-a2dd-440473657dba@luc= ifer.local/] > > I am even not sure what to do with the other 3 patches. They look > correct. But I should not take patches with an unclear origin, see > https://lore.kernel.org/all/2f824be3-7b30-41c6-b517-de1086624171@kernel.o= rg/[https://lore.kernel.org/all/2f824be3-7b30-41c6-b517-de1086624171@kernel= .org/] I'm gonna arrange a video call with someone to fix this