From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta1.formilux.org (mta1.formilux.org [51.159.59.229]) (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 353BD31353D; Fri, 16 Jan 2026 15:30:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=51.159.59.229 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768577462; cv=none; b=AVmr/VsrIztrry73/x9mUAAlinNbtIOStPULsqa+U7Hc12na3pKW26FO5wGh8KMn5oKMWqBRHX/MEX5k+i+3iKA0pD4uhSezLva9x0IJPF+O5a2Me8r8iV81IKTtg20qbEykrFmOBST9Hp+oXLMvdnNDLX+ovfSwAJsBolNxfjU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768577462; c=relaxed/simple; bh=kbHw7+rc6Z8LM341+M1CMDt5DuBgCHv6q6/IBch5m1U=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QODjDB+/ItXx36+AfTb7EYB1BPvoinJjQr86MnbGqJRXVKs5sjjhfmtMjEeIdPUQUP7TXHwEmWeJQAZCwymGA2ahZyIRGU8fAd21ThyJsOiYXl7Au1P1GRRsieA/K4hpfC5Mf2kNeDNE4ODetTzQ/dCIGbFEgOi1+N4sLqYQT0w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu; spf=pass smtp.mailfrom=1wt.eu; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b=RK76yaBk; arc=none smtp.client-ip=51.159.59.229 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=1wt.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b="RK76yaBk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1wt.eu; s=mail; t=1768577456; bh=/bAHalk7oV7U9/SqHdwaXMjed1woGXQlXW+Ro+klo+U=; h=From:Message-ID:From; b=RK76yaBk+XlcaYxZIHH2o5JXBhRbvZckoQ28GImpGqzAtufEWMeNwqqgrcUkt+5Xn LkJ2K6FWwvKtPXdubGdg0zQvYq1/ZLZxT3h0plnYy5+M77j2x+nrj4IUOaxxtAeRhb yr+iX4jEUK4zM6Azlr6nwPO5IqDIYur4wA5+kRYU= Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by mta1.formilux.org (Postfix) with ESMTP id B953FC0BD3; Fri, 16 Jan 2026 16:30:56 +0100 (CET) Date: Fri, 16 Jan 2026 16:30:56 +0100 From: Willy Tarreau To: Stephen Smalley Cc: Christian =?iso-8859-1?Q?G=F6ttsche?= , Paul Moore , security@kernel.org, selinux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: Suspected off-by-one in context_struct_to_string() Message-ID: References: Precedence: bulk X-Mailing-List: selinux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Hi Stephen, On Fri, Jan 16, 2026 at 10:12:15AM -0500, Stephen Smalley wrote: > On Fri, Jan 16, 2026 at 3:16 AM Christian Göttsche > wrote: > > > > On Thu, 15 Jan 2026 at 21:20, Willy Tarreau wrote: > > > > > > Hello, > > > > > > we've received a suspected vulnerability report on the kernel security > > > list, that was clearly generated by AI and really not clear at all on > > > the root causes nor impacts. We first dismissed it and it kept coming > > > back a few times. I'm not pasting it because it's more confusing than > > > interesting, though I can pass it to the maintainers if desired. I'm > > > also purposely *not* CCing the reporter, as the address changed a few > > > times, and once you respond you receive a new copy of the same report. > > > Clearly this bot deserves a bit more tuning. > > > > > > The report claimed that the call to mls_compute_context_len() didn't > > > properly reflect the size needed by mls_sid_to_context() due to an > > > off-by-one that would result in the trailing zero being written too far. > > > Initially we thought that was wrong since there are +1 everywhere in > > > all lengths calculation in the function. But revisiting it today made > > > us realize that this indeed seems to be true: the +1 that are everywhere > > > are in fact due to the surrounding delimiters, and the first one that > > > appeared to be the one accounting for the trailing zero was in fact > > > for the starting colon. > > > > > > In context_struct_to_string(), we have this: > > > > > > *scontext_len += strlen(sym_name(p, SYM_USERS, context->user - 1)) + 1; > > > *scontext_len += strlen(sym_name(p, SYM_ROLES, context->role - 1)) + 1; > > > *scontext_len += strlen(sym_name(p, SYM_TYPES, context->type - 1)) + 1; > > > > I think this +1 from the type name length covers the trailing NUL > > byte, since mls_compute_context_len() and mls_sid_to_context() cover > > the one byte space for the separating colon between type and optional > > MLS component. > > That is correct. The MLS portion is conditional on whether MLS is > enabled; hence, the +1 for the type length computation includes the > terminating NUL, > and then the mls_compute_context_len() starts at 1 for the leading ":" > if MLS is enabled. The code could admittedly be clearer but I don't > believe this is a bug. OK and I, too, think that mls_compute_context_len() stands by what its name implies. But then *who* is responsible in all this chain for allocating the room for the trailing zero that is being appended at the end ? Or is this the last +1 of this block maybe ? *scontext_len += strlen(sym_name(p, SYM_USERS, context->user - 1)) + 1; // ':' *scontext_len += strlen(sym_name(p, SYM_ROLES, context->role - 1)) + 1; // ':' *scontext_len += strlen(sym_name(p, SYM_TYPES, context->type - 1)) + 1; // \0 ? I'm asking because nothing is really clear, and if it happens to work as intended, it's not super clear why. thanks, Willy