From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 CCADE3537E8; Mon, 12 Oct 2026 00:56:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791766593; cv=none; b=HF9frpVbIPmSon3L/myLODxnyeOlGpEbqDkn7lCKDCbNbGt8rN7IB7UFiVINHYIkmx7guFkZ28aCnt60Liezu4IcOfHdh1arhJilXtT6Tz1yBHqsoGGM3yGqjdvXshv9DO7GMECn71970vhc6efY3WJESYnhmbOijgXVfb4W+eM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791766593; c=relaxed/simple; bh=fgEYWGJ2o79ZogsVquNbtLGhVkZVUJInYR7e8viFy64=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OrfIPEpJhqFbub3lxX2VrBwpAJk8MXSpXWmfoJSQq+1LukeydNRu0ZB2Clj5PYCqotz8jdznjaVruli2oSrMnK9vIScb0Dje0HFWAoyhkyQ+99csv3hjrQE3mVzIGz1mfq4zX+AfJ20IdqHSSqJqnjhbn4d+VeTV78Ui/u/NF/g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Srp4lxTv; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Srp4lxTv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3BE541F0089D; Mon, 12 Oct 2026 00:56:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1791766588; bh=hxf53qqklnBrLDOnVa563Rz7Xv1pTGUtJCKz14BmezI=; h=Date:From:To:List-Id:Cc:Subject:References:In-Reply-To; b=Srp4lxTvswzQGSZurZdIgokznIEj5wyrJNY9T77hd+9PMBPDY7gvvfunlGvn3ilAt c3UqltVrr8pDMp7TpDjaT+8DWh+uNsnVzDM/cCacLNCkmQrqU91rplRALKRe2zQEwJ jMlbkTkanGJ47er7L6/E5P3rPXC8cQsk79+DBESejMhm2sHhgCTx5z2mewZh/Q+eCS F8OdoYFePL+Ri0/RcYD/MmZKZu+FdwiV3IGzDWFNxqUREJ9KJfdvF45vhgPbd5Rpxn 5C0t0G6buQIudJ3rTCmzqaMebg7XdlTR/4PYtBXFKymc2w62JaoqVSbDQu81sYb3fr 9hXGvCVno8tUA== Date: Sun, 11 Oct 2026 17:56:27 -0700 From: Kees Cook To: Alejandro Colomar Cc: Alejandro Colomar , Andy Shevchenko , Bill Wendling , "Matthew Wilcox (Oracle)" , Andrew Morton , David Gow , Petr Mladek , Shuvam Pandey , Steven Rostedt , Jonathan Corbet , Sergey Senozhatsky , =?iso-8859-1?Q?G=FCnther?= Noack , =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , Masami Hiramatsu , Mathieu Desnoyers , Jiri Kosina , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , "Christophe Leroy (CS GROUP)" , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Shivaprasad G Bhat , Thorsten Blum , Alison Schofield , Dave Jiang , Greg Kroah-Hartman , Guangshuo Li , Ira Weiny , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , Vishal Verma , Randy Dunlap , Shuah Khan , linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-security-module@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, nvdimm@lists.linux.dev, linux-doc@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v4 05/11] seq_buf: Add seq_buf_strlen() Message-ID: <20261012005620.466497-kees@kernel.org> References: <20261003035906.too.263-kees@kernel.org> <20261003035921.1918874-5-kees@kernel.org> <202610040023.A3865A6@keescook> <20261005112209.1e47fa-kees@kernel.org> <20261005155839.d5d200-kees@kernel.org> Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Oct 05, 2026 at 06:43:23PM +0200, Alejandro Colomar wrote: > > Yes, though not often: the sched_ext debug dump builds a nested per-CPU > > seq_buf from seq_buf_get_buf(), which returns a size of 0 once the dump > > buffer has overflowed, and it handles that case on purpose (see the > > "$s may already have overflowed" comment in kernel/sched/ext/ext.c). > > Hmmmm, so IIUC, it is a sentinel value, and not really a buffer size? It's the real size of what's left. seq_buf_get_buf() hands out the unused tail of the seq_buf. Once that has overflowed there is no tail, so it returns NULL for the buffer and 0 for the size, and sched_ext initializes the nested seq_buf with both. So that case does get the NULL; the 0 is how much room it has. > Did you consider not holding the size of the buffer, but rather an end > pointer? It also allows you to find how much you can write to the > buffer, but has slightly better semantics: the end doesn't change if you > advance the position. 'end' can only change through reallocations > (which I don't know if you do in the kernel). The size doesn't change either: it is set by seq_buf_init(), and writers advance "len", an offset from the start of the buffer. seq_buf never reallocates. An end pointer wouldn't remove the empty case: buffer == end is the same condition as size == 0, so the accessors would still need the check. It also makes overflow harder to record. seq_buf marks it with len == size + 1, and the matching position pointer, end + 1, would be weird. Changing the representation would also means changes outside lib/seq_buf.c, since tracing reads seq.len and seq.size directly (trace_seq treats a zero size as "not yet initialized", for one). I'm not saying that's a good thing to bypass the API, but rather that such a change should be its own series. -Kees -- Kees Cook