From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 539B92848A7 for ; Thu, 26 Mar 2026 13:38:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774532293; cv=none; b=Jzh9e0Jjk/Pm9LfInalxsKeeID+QYrwCHbFjjLBbSrdFxhP3ZrkolHiSft4vCFAW6VKDBpictabEgSeOfGNnaEznIQ/ihgBMI33VNbKEqXCKFYJ6PWFj0paoi02Bcs8pIlZWO2gocMsTXhEqirLoycgCRJaoIHM0A951AI5vt8E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774532293; c=relaxed/simple; bh=vZsAtNU6zYKW9aOARJd0R3lEqyPM9i+PAiKkxXy8ZXY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mhgYm+p6peVf9McVLwo57Ekzqni5QlaEHkbsijs+x9DFV8FIxcNEGOHnObzcQ9PQfDm56mWv+asTvEmyyh25/OZeWPFa8u4gruV2ab9DcYkbUlS3v8PcydwSilqnbHaVLNYWgFeOKJL5zBj5zJ1mFMF+01Ba3ihgr7aHTymdD5E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=lEyFRoKy; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=G4h7ESwX; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="lEyFRoKy"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="G4h7ESwX" From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1774532290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JsDTv0lgDybe2OAfT0gUVH70dFo+Xkn7yYhLH1y+pxA=; b=lEyFRoKyGQUitspV2PyAw/J7Q8dwJx2HJA4Ye2KRcy+jbF0Awyt88rwyjOdtyzCJd2g0Qh NS1ge7LWoKfe6Suhg3X85I3FmkFO6SvfSfG3FvSwA8YS6D7Lm+nczPtSGFLe3oAK7IYLCw PTudyrbwI+iCl5UFgy6jdwRl7VP3V0gBEnL10TGxLw2AmdW/IPuN+Eq7pRt0iYvWaJdUVl vJ97hdKXlbpwiSUvDagquSxMdEB8YWIocBIPz3bEARvFPF8biAzpcTnKB4/oxBAO87wh1b nk5P0KhUtsxUkL+TN40leZH+fXDO8awsSsAGqjh7Q7boNCgAJ5xn8kYvQQhw0A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1774532290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JsDTv0lgDybe2OAfT0gUVH70dFo+Xkn7yYhLH1y+pxA=; b=G4h7ESwXlJQc5kgPduSKOyxjFUOCNP3gDDhjh0tUubhpGevUmP3g84Wliz8BFsg2L+SsAR pZakEOvpw1g4IxCA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 2/2] printk_ringbuffer: Add sanity check for 0-size data Date: Thu, 26 Mar 2026 14:44:02 +0106 Message-ID: <20260326133809.8045-2-john.ogness@linutronix.de> In-Reply-To: <20260326133809.8045-1-john.ogness@linutronix.de> References: <20260326133809.8045-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit get_data() has a sanity check for regular data blocks to ensure at least space for the ID exists. But a regular block should also have at least 1 byte of data (otherwise it would be data-less instead of regular). Expand the get_data() block size sanity check to additionally expect at least 1 byte of data. Signed-off-by: John Ogness --- kernel/printk/printk_ringbuffer.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c index a3526bdd4e10d..aa4b39e94cfa2 100644 --- a/kernel/printk/printk_ringbuffer.c +++ b/kernel/printk/printk_ringbuffer.c @@ -1308,8 +1308,11 @@ static const char *get_data(struct prb_data_ring *data_ring, return NULL; } - /* A valid data block will always have at least an ID. */ - if (WARN_ON_ONCE(*data_size < sizeof(db->id))) + /* + * A regular data block will always have an ID and at least + * 1 byte of data. Data-less blocks were handled earlier. + */ + if (WARN_ON_ONCE(*data_size <= sizeof(db->id))) return NULL; /* Subtract block ID space from size to reflect data size. */ -- 2.47.3