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 CDE2F2D061C; Fri, 16 Jan 2026 08:26:05 +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=1768551968; cv=none; b=F6r9Ju9xkVojNZe6uAtjuVAl6sqzbd2FDHl13vfumetTBmgIjEiWyC7oJx0vBIA1Kt0UvMJDxQVDyTsmux6NYdbhqm3B6yHZxcIRD0w83WzqAzuwurmv4tne8Ay20fRSzL2+VWbf2mdF5aN3XmLgor+xbGiBuge4aFTm0vH8BRA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768551968; c=relaxed/simple; bh=MzL2R7Oe5wUS73kI0LzlF7hHjo/nzk1CKa4Pcgik384=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OAVCB4V5cXkyY3q93lqfMkNv6eIhwMZOiF80qnBVd/OMPw1BgHL49GQAQkjJ38LDcggUBcDyj3fPs04WMvwE+We6YrzCymauYFRlrgy1QS6209PJzFpW2bQEQAd+jhvvk0NTrhwK6podk0jtGi4c3pyLVS7foSBxAJJYu+93Eu8= 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=FHxGOKVO; 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="FHxGOKVO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1wt.eu; s=mail; t=1768551963; bh=ic2dlkhdj5/QSbu11Kb4rCwu1gTlxcwfYbqvbPBJfbg=; h=From:Message-ID:From; b=FHxGOKVOr4P92HQWXOtwZxT3Nyyn4pBWK+7HdlAw/K45ZpAtggl8hKjpFVUsWc5h0 KLIUuFtexHGdrOak+m5+g5eJABbOboibszNAxyiF7E+z1eoAuVkhnOb6j+X1uQRXSV k4BPr8LmpPn6VP4ap7L+oNfWVpW5m6myYBZPHWuQ= Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by mta1.formilux.org (Postfix) with ESMTP id C4FAFC0B8B; Fri, 16 Jan 2026 09:26:03 +0100 (CET) Date: Fri, 16 Jan 2026 09:26:03 +0100 From: Willy Tarreau To: Christian =?iso-8859-1?Q?G=F6ttsche?= Cc: Paul Moore , Stephen Smalley , 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: On Fri, Jan 16, 2026 at 09:16:10AM +0100, 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. Sorry if I'm not clear, but my point is that above each strlen()+1 seems to serve as the length of the text + its colon delimiter, so it covers useful chars and excludes the trailing zero, which is fine. > > *scontext_len += mls_compute_context_len(p, context); Here it does exactly the same. > > > > *scontext_len is initialized to zero, is increased by the length of each > > appended string + delimiter, and used as-is in kmalloc() a few lines later: So now we're allocating an area of the number of useful chars, not counting the trailing zero. > > scontextp = kmalloc(*scontext_len, GFP_ATOMIC); > > > > then filled by sprintf() then mls_sid_to_context(): > > > > scontextp += sprintf(scontextp, "%s:%s:%s", > > sym_name(p, SYM_USERS, context->user - 1), > > sym_name(p, SYM_ROLES, context->role - 1), > > sym_name(p, SYM_TYPES, context->type - 1)); > > > > mls_sid_to_context(p, context, &scontextp); > > > > And finally the trailing zero is appended: > > > > *scontextp = 0; Yet we're emitting it. At least that's how I read it. Willy