From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3610280CFB for ; Thu, 16 Jul 2026 01:42:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784166125; cv=none; b=CpbWTJp3bqnmjCxTMKqVqCnay1a1+UiMg4wpYrDOAcH0V8EQXUdZM8VzRVy51k05LPWhRmYSdUZXClhPGZatRcQ3Y8jawXflIZW1lthPqF198AsxN91wjfa3/DLVWif0x0EpIU6pTvGQZ5hTdWPJrspujUSAn1CONcXvmeAVFuU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784166125; c=relaxed/simple; bh=Rm3zfzbiec/4wmTDpC28Dh2BIIMF1DdpynZYCJmLLXo=; h=Date:Message-ID:MIME-Version:Content-Type:From:To:Cc:Subject: References:In-Reply-To; b=FyAkuWH6vRDMVdW/WRh7tL2nFgfVF3DKpDs1zucSftsh3gUJV+5pTkX3iG6GWS4PmgEKW75EfzKccRwF8h7nSMzU8+cLP2REo3hxUc/dgU5TBLhZxzqfMuL/gk+p9CN/ZtoAafsqS2QSgAuFziUQUo01cfPXyqq55qo3Fsqkj3c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=paul-moore.com; spf=pass smtp.mailfrom=paul-moore.com; dkim=pass (2048-bit key) header.d=paul-moore.com header.i=@paul-moore.com header.b=S5imNZSk; arc=none smtp.client-ip=209.85.222.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=paul-moore.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paul-moore.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=paul-moore.com header.i=@paul-moore.com header.b="S5imNZSk" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-92e65e18969so6563885a.1 for ; Wed, 15 Jul 2026 18:42:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore.com; s=google; t=1784166121; x=1784770921; darn=vger.kernel.org; h=in-reply-to:references:subject:cc:to:from:content-transfer-encoding :content-type:mime-version:message-id:date:from:to:cc:subject:date :message-id:reply-to:content-type; bh=pAzFFJdbYYl7mHVxFK70YlTaNUU7tEmfvu8LFVmQ8u0=; b=S5imNZSkpkNGnY21UPbLWzr94ZuxD/K2yqbm5bS6xfUXiMvA6iiPt2qHcpkWcJrfAi GlYfgE/0BH9yhLN6KKWEdKPTm7pSiV64pjFVlIBjTTIeldqPppwOA7SDI1z+Hlw9OOYp CrRCPq7oY9sNq9OAN0HIDMpy46l4CwE+CWreadqjWNuvSZqF3z/GpV/VWtuFmh+zIItz UpxyYxnbkyHv4mvibwOOSelVXtV5IVk9qtIkcIeJSVxgvKZiNyT3JCyRVTA887DTCwIb AeIYUKkvfdLoeNiJShuQ6oCItR+CpWSSsJu5HwYAZl6sE3tzMJs5PnEN2ofmjOUCbAbc Ph3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784166121; x=1784770921; h=in-reply-to:references:subject:cc:to:from:content-transfer-encoding :content-type:mime-version:message-id:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=pAzFFJdbYYl7mHVxFK70YlTaNUU7tEmfvu8LFVmQ8u0=; b=POUg1+hf6mS9LDkMm0GC6RjXxgnOq8Hx4Ast1xnUYmCg+h+z6Sg57H3fEyiJTtAzoy JpLn+Z2FkQFss30DHFe4qkpBPMY8SspNwkAYAUoVwgeHL+UERS39AS+s/ju1kN5S3u8s Mk6VtA6iBVEVjqpsc2sIeLoac1T1fbLF9AgOD4O6gAG5EKdyKWe4REY0zWEmLjWAy7/N 99q1V0S8riGer3ZWocL+rjVdkQeJpZo12DCnEmCx0+knMN99U3s2G8R3Qh3v/XpCv7ZQ EXhSbQ4lBPfLMGIbKzWqSY8DdaCA7ah/zDIbZlrFPdaB7e2sUx7luEuqLWEXmYQcjTQx JUiQ== X-Forwarded-Encrypted: i=1; AHgh+Roy1KLjHDGEfBcR0yNOUbbLJ/9uDYcA+PZFDcT/2Ypy64mO9PPN4wbYg+8FSU/vy6vis4lH+ki9vrQ2dtg=@vger.kernel.org X-Gm-Message-State: AOJu0Yw29Nr96EJ48XCK7nw2lWgh7JPCaCJsmVxooWfDqTXdjqjTTHS1 3uuZqmyxX3sZqeEJxAPQO+mDXSLXvix8tUlrDaeLeBaRNOrE9gC4tpOf+VYZPib7RQ== X-Gm-Gg: AfdE7cmYIWoxYWBjmcj5MxRM3iYvvMo1A3qKFY7TPI8wL7BE9Q7vYd+UV+XphEokXal 3k7CEcAjkh2qI1Vt8MHdcIY8SeH2KC7VjUcoEevvkMIzb6pQous/ymPvnwopTq67w06tEDbIoAV xgjNw6fXsCl+uz5BeGhC3S+iASBuofFUVKvRRv+UXvZeZ064ugy0+ldEIKBsUNxst2atNmouJ59 pvswYA+gdi5jps9GbB4OkgATa4F8QiYRtf4V0w9V8+B8L4bpp+BxPY0UZ456RshX5F9SxI1qebX 2n19ZZCDuKHnrYi40UAxQAX5zBPAGWWsBKfW0IHxXytlbCqwim7G+anQVbixP0aZZ2mYxoEFynE NBnYLc8Uu0BcOIc0cRQIOYXvnZJxeFsmLS3LWwgpRjtU6cbnR/FpyYf4W01dY+i7Hqs+LsoTCB+ r9YoAHKZa9XbeWudYU2hgK7H7mnZZyBW04CKvSz7iEo2ucY68= X-Received: by 2002:a05:620a:2546:b0:8cd:d688:7aef with SMTP id af79cd13be357-930a5eff868mr68030885a.19.1784166120795; Wed, 15 Jul 2026 18:42:00 -0700 (PDT) Received: from localhost (pool-71-126-255-178.bstnma.fios.verizon.net. [71.126.255.178]) by smtp.gmail.com with ESMTPSA id af79cd13be357-92ee5cf7ab2sm1796335785a.30.2026.07.15.18.41.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jul 2026 18:41:59 -0700 (PDT) Date: Wed, 15 Jul 2026 21:41:59 -0400 Message-ID: <2e52b3433b9cac9466eab694752a7603@paul-moore.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Mailer: pstg-pwork:20260715_1900/pstg-lib:20260715_1853/pstg-pwork:20260715_1900 From: Paul Moore To: Ian Bridges , Stephen Smalley , Ondrej Mosnacek Cc: selinux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] selinux: compute the IMA configuration settings string length once at boot References: In-Reply-To: On Jul 14, 2026 Ian Bridges wrote: > > selinux_ima_collect_state() builds a string of the current SELinux > configuration settings. The string lists each setting as a name and > one digit. The length of the string therefore never changes, but is > still recomputed on every call. > > Add selinux_ima_config_len_init() to compute the length once during > selinux_init(). Update selinux_ima_collect_state() to use the stored > length. > > Suggested-by: Paul Moore > Link: https://lore.kernel.org/r/df755e0282dab3b932d19aceab71b7d7@paul-moore.com > Signed-off-by: Ian Bridges > Reviewed-by: Stephen Smalley > --- > The produced string is unchanged. selinux_ima_collect_state() now > depends on selinux_ima_config_len_init() having run. The call sits in > selinux_init(), as suggested in the review of the seq_buf conversion. > > The length computation itself moves verbatim. The strlen() + 1 on > the string literal could become sizeof(), which counts the > terminator. That rewrite was left out so the moved block stays > identical to the applied code. > > The patch was tested as follows. > > - W=1 build of security/selinux with CONFIG_IMA=y, zero warnings. > - A userspace differential harness compiled the old and the new > functions side by side, covering every combination of the settings > and the policy capabilities. The outputs were byte identical. The > stored length was an exact fit for the produced string in every > case, with no overflow and no slack. > > security/selinux/hooks.c | 3 +++ > security/selinux/ima.c | 33 ++++++++++++++++++++++++--------- > security/selinux/include/ima.h | 4 ++++ > 3 files changed, 31 insertions(+), 9 deletions(-) Merged into selinux/dev, thanks for doing this. -- paul-moore.com