From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) (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 3B9E827E07A for ; Mon, 30 Mar 2026 16:30:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.40.44.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774888224; cv=none; b=u57rcGLIZdJxfZ9f8n8ZNvlPaW1ZdEmpYpleZinC9d2zZktMztqL5S/yG0ELQ9ejP1EEKEBDzOKgAEpKm7eBTPQBP1nfXMPH0O8Ijiz3LFDJ2lIgVkYNlcUuewAm0EmNhrn2OAoqPvTLd6oEEoyugv6aCaqHGZovTentfJyPndw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774888224; c=relaxed/simple; bh=zDT2M+w+uE/U9gmy8yc9RnhmhfVE3bqYJ0887ZZuqWk=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MTgtoB1fWHmagvIsZe4jTac6q6MnYkE/jYagEh1HD+IrO5nIa+XMZt1NayyzlWOlg9CEUkojym3TVozSFcunlSoIThe1l8PxHOxNv0wEwYLVmr5ODkPhG9h92SaHdBDKvVx/slu+kw6fl06yOEZMu8XHOJr6ZOZORNhfYI/UezE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=goodmis.org; spf=pass smtp.mailfrom=goodmis.org; arc=none smtp.client-ip=216.40.44.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=goodmis.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=goodmis.org Received: from omf15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E001FE0E2B; Mon, 30 Mar 2026 16:30:15 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: rostedt@goodmis.org) by omf15.hostedemail.com (Postfix) with ESMTPA id DF8DA1C; Mon, 30 Mar 2026 16:30:13 +0000 (UTC) Date: Mon, 30 Mar 2026 12:31:09 -0400 From: Steven Rostedt To: Josh Law Cc: Petr Mladek , Andy Shevchenko , Rasmus Villemoes , Sergey Senozhatsky , Andrew Morton , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/4] lib/vsprintf: fix OOB write in vbin_printf() when size is zero Message-ID: <20260330123109.365934af@gandalf.local.home> In-Reply-To: <20260324224940.50508-3-objecting@objecting.org> References: <20260324224940.50508-1-objecting@objecting.org> <20260324224940.50508-3-objecting@objecting.org> X-Mailer: Claws Mail 3.20.0git84 (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 X-Rspamd-Server: rspamout07 X-Rspamd-Queue-Id: DF8DA1C X-Stat-Signature: xk7yqd8htk53ie999wrikhw8hb1ih7yp X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Session-ID: U2FsdGVkX1+IOIvlzyxVlqzcvrdO/QksNob1KVo1Mng= X-HE-Tag: 1774888213-505213 X-HE-Meta: U2FsdGVkX19SyvH48EoFBhI6D0e7FExj4ujoJHxuMagJoY3UmQoRihLxex+Y+4lHV/e4izW8/yEN65sCKhGRrXehhZ336rbUwBwRv7aiKifhlSbl0fE6eIfle6VXM2T/XXcFok6pk9wNGhBQmA8ZD30zafzt3tDPDWF8WKGNMoisBd4qB5hdLyPwguDDqIToJiToTBxH2U1j1doIoxMJUJxibxT/dA6b5+FjeMw7Yc8bYXwDfSIzW4JyOgy6aQH/i6mR93qCe953elbxW/F5W1b2nXIiSn0MJqsnB5KfFHa6JL48v3L1MFpsW6VfeiDk5St8igbPJSoUc0JsJqZi/0RYJTGk2zZu3uFkY3+CebGHdnY3UD2PUW1oeOJtVazi On Tue, 24 Mar 2026 22:49:38 +0000 Josh Law wrote: > When vbin_printf() is called with size==0, end equals bin_buf and > the else branch writes end[-1], which is one byte before the buffer. > > Guard the write so it only happens when the buffer is non-empty. > > Signed-off-by: Josh Law > --- > lib/vsprintf.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > index 7898fb998b21..72fbfe181076 100644 > --- a/lib/vsprintf.c > +++ b/lib/vsprintf.c > @@ -3234,7 +3234,7 @@ int vbin_printf(u32 *bin_buf, size_t size, const char *fmt_str, va_list args) > spec); > if (str + 1 < end) > *str++ = '\0'; > - else > + else if (end > (char *)bin_buf) > end[-1] = '\0'; /* Must be nul terminated */ instead of doing a comparison, couldn't we just check size? else if (size) /* do nothing if size is zero */ I'm guessing this would be slightly more efficient in the assembly. -- Steve > } > /* skip all alphanumeric pointer suffixes */