From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385050; b=JfV9sEPMH6eMrk/F+MuseodzreLlHj7ZDi96B9yvdNzZ4E5GGPKDZg9InkKCpuOpNrxR RbBi9F7iv9Roo/wn4qqUFbpP+7MsCDezg4S4Y97Qkd7qza/TT6TP1zy+7ZwQ/rmSzXRmW 1WT7Fc3KjE4coCsMPqAxaodKvBkvU8Gr0bVADhiCAxcoPl5cgn3UykcU7VacSPcIAwXL+ wQYCLtChDw5SntvUc9ZSwWP8y4elVHKZP0oBHi0C7DhQuDoW1fXEQyOTJFedVTd96McoX LXpLviquyN+Yk7kLpsGOzeaYElUKULr5VF+yW2AJ1y76giFEN+2OaBLlZeMvw/FjBsA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385050; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=X5iqix78U4bIkDTqUP/6YcofrHv8jRCtsLSmor8TbmA=; b=NjTRjJX/I0BBHQWN19mQvhhXb4wgI/aeE0FrwNd816HnmX8Feub6DkJJfKFVr2KAnU/2 Kdc5pxCSUzy6APmdnva3viPoPSc5Zm60v7XowZoRz50UyM0ENY0xImVHeRVa5+XEwHWJu 5YSFmbrHbSRj76NcT85vk8GMLu6U2HDr1QGidhoUCaA/mkMdXf9KqrkODUoFl6bui6x5j HdJCjzRZL03wwcUhujDqttSUyG3TrblaXNUJ4YC/uILyVUol2F/XRKOogGPEkUDat7pEi SGMjqL3Qh+z8JMisSG/u7vIi3J6o+/V14XsoMftm9LunGJJKygCgAo0s3BRdpVw7/LA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=tdt5xvie; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FEBB606A322; Fri, 4 Dec 2026 11:50:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=tdt5xvie Received: by smtp.kernel.org (Postfix) with ESMTPSA id D12D51F000C2; Fri, 4 Dec 2026 11:50:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385050; bh=X5iqix78U4bIkDTqUP/6YcofrHv8jRCtsLSmor8TbmA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=tdt5xvieOVdrunjc2T3q/zzHbCNxBYkn5bOMXyvnM0uwaq9BmcktPbgcG4SDeHsIA SyTtnnX6M9j4Ief+f5uPutYnU1zUwZLkS5TmVpFbYN4ggnMWf9eG8vuoUqh9AiQ/zR ItwNbYN5r6gkUXTtHSZxFKcGUYxsSuGQlAGFSMB8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kees Cook , Sasha Levin Subject: [PATCH 6.6 0397/1167] seq_buf: Do not print an empty line from an overflowed seq_buf_do_printk() Date: Fri, 4 Dec 2026 18:57:04 +0900 Message-ID: <20261204100712.366721381@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kees Cook [ Upstream commit a09fb764832dd7dbb9ccc38a9830f7294889c8ae ] seq_buf_do_printk() prints a buffer line by line, then prints whatever follows the last newline. When a string has overflowed at exactly a newline, an empty line is printed since the pointer hasn't reached the overflow mark of the seq_buf. Switch to just check if the string is already empty and only print if not. The only caller is the memory cgroup OOM report, so this could only ever add a blank line to a report whose statistics already did not fit. Add a test that registers a console to count the records that seq_buf_do_printk() emits. It counts the records carrying the test's marker, and the records holding nothing but a line feed that arrive after one, so that unrelated kernel messages do not disturb it. Both states that reach the flaw are covered: exactly full, and overflowed. Tests passed under qemu on ARCH=x86_64 with GCC 16.2.0 and CONFIG_KASAN=y, and on big-endian ARCH=s390 with GCC s390x-linux-gnu 16.2.0. Fixes: 96928d9032a7c ("seq_buf: Add seq_buf_do_printk() helper") Assisted-by: LLM Link: https://patch.msgid.link/20261005155708.1471260-1-kees@kernel.org Signed-off-by: Kees Cook [ sashal: Dropped the test-file hunk because the KUnit test file doesn't exist in this tree, and applied only the one-line seq_buf_do_printk() fix. ] Signed-off-by: Sasha Levin --- lib/seq_buf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/seq_buf.c b/lib/seq_buf.c index 23518f77ea9c5..1cd32ae73ad32 100644 --- a/lib/seq_buf.c +++ b/lib/seq_buf.c @@ -118,7 +118,7 @@ void seq_buf_do_printk(struct seq_buf *s, const char *lvl) } /* No trailing LF */ - if (start < s->buffer + s->len) + if (*start) printk("%s%s\n", lvl, start); } EXPORT_SYMBOL_GPL(seq_buf_do_printk); -- 2.53.0