From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) (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 1284523C4FA for ; Mon, 13 Jul 2026 22:15:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783980933; cv=none; b=cNSdC+2KAicmpXYFTe4BXKy1ADkPyc4DsWEwXzW0S2uavt00VB4iA4HDlypEDDH0yNzJc7vu2yBumENcYjykFgGjOYRWfcPmYUEpuoZQwxbNDpCMYQPImMTfsLWPSKkHp12iIRXQA4r7dOyKuqNQN2w38WKP4JrdvBn0pMEmnd8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783980933; c=relaxed/simple; bh=EDMAekzapluN8qvqLwwRmxBiWYLSDHH4j1CTBMpYI8c=; h=Date:Message-ID:MIME-Version:Content-Type:From:To:Cc:Subject: References:In-Reply-To; b=XQ080Qe3XrU/6dSBWc5L/yuo0PEGzKc8XDe06O9SPYXC6J4mdEqFpSZejomRF6xum8mi78wDBLYTWy7V6xNb9pVQh0GoIEPn1sew8J8D+I912j1Av3jEAltw3ikYcgsCf5y8Q71gGqsXjFzphMKDhnd2hR+V88qLBsNX16S4Uu4= 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=JZkhv30v; arc=none smtp.client-ip=209.85.160.177 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="JZkhv30v" Received: by mail-qt1-f177.google.com with SMTP id d75a77b69052e-51c5382806fso2818231cf.2 for ; Mon, 13 Jul 2026 15:15:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore.com; s=google; t=1783980930; x=1784585730; 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=6knqno33u0gKFnShVvAy1vOVQidX1D6I4tvt9i4jmuw=; b=JZkhv30vhx+vGk+seNoIcsgrBx5LtWeViBMuOjT2j5C9vxlYY4imKsV2zSxNeZEq7c wN4L+CzCOX8RHrf/s7zsbFG48UPBv0XXej9CHF0hKl4/dExkdtF54ADrSTNvDhjwVJ7e FD+nP3btnYSyBbdK5tUmriuesadgiHx9nr5u5WE82b8Y9PllEAKH5SrtHln7LoeN4x4d i6ZnJc10oSpTYBVZhbVrJr9TAdu5qNKA4jEtissEuB+c9AsgAhQWTMh7n01XZKoh9nxH vcwpfqE+gAlADDOfSxQceSHQ8m8bkMTTKAfqbpfeUWSqgl9407GVUzmkcDcmzt/JU71s xTPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783980930; x=1784585730; 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=6knqno33u0gKFnShVvAy1vOVQidX1D6I4tvt9i4jmuw=; b=gvCT9OOaaxT5G2J9wzO8OWU+4muJbmXhW97KLaF+bAXksL4+wnF+mD/YPbZe6UPM6X 1byznI4uZ1wENuxbz5VTLhvw2xC8Zd+PFHUhVDxOx7GR6U7PaXVqHQT1wjrx7Rtbd9aA elbWNbdswE79KV4qHuIkldNNinT8VcHt33gIbnDr+xDoWuKJVYiymsB9sjVsJdzAgSvm udf2+oYe67q1ITxWI1d+qcI7ZmqrGzK/c88nY6a2AP0QeouUd1FBHHrPa2+cvooj1GU+ MOaa3yc3BAwr7Tb381euRI2vDoRMHk0stLdJ9qPli1I3597G7AQS5V4gruXhseg+c8ob L+QQ== X-Forwarded-Encrypted: i=1; AHgh+Rqd0uC7asv3ETNzriez4k8gO2gpNnPHZDwjEYVTH44LNfwkptFRhtYcfAGb9qWiGFVPvoDgcDI04OoOG/E=@vger.kernel.org X-Gm-Message-State: AOJu0YytD8Foyzy2TQu4hp1LvBUr5lYEJCclP9PBOqZfxUTJl2fuvDyN ich67jxXwlCR64koTc5ku/MsAQWxdChuQ3UzjLWwiid5LKS0hawA8/pbDho/qMLpzQ== X-Gm-Gg: AfdE7cnGGEwGXeTjEbaDabd9d62QYnz5dp7zlOkdIeiccZ1YI0QKXIDEI8u2EAHTE0o Jj2X/TjGe9nnDu6a6neylrKRXM4KHwsm7gRBO+4bRzQPZE6WLIAXiOpqCHudSzPcCUyRlY/9r+d ZWYIdxVazI/HCsXFZ6paDLmvDQLQ+frZzna1CevwGOJbiGMiZ/wnDNwv17ktj43qFga6QWLTgTo 4MTCRIOmpyepJEUhGYB7VDZqAvOcvi6tDh00AaX85giMRom3P4Sa5FFGfHY/2p0DRcLEZRciAvY sfg9uRu3RodffoURUznXiOQpu0WBT5jfnQx+jS/2bJ8RKJWi+MIEqXtYTflnZNfdK2oQZjzeF4m 4i08rLUQqn+RhL6PCkOo3yIVCNXN431hEGKVuzb8APALhhrxz4kHozbcyAmAXzYMg0PRbcVW4Bd QVxoHTX/QzaFMTrn8sgm9ZNCwnz7qE2fCUwqVHhGwOy7Rrn8ataL5/6pJSvA== X-Received: by 2002:a05:622a:2d5:b0:51a:8b64:69e0 with SMTP id d75a77b69052e-51cbf0dff29mr107693501cf.11.1783980930061; Mon, 13 Jul 2026 15:15:30 -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 6a1803df08f44-8ffd50df5e2sm144312526d6.4.2026.07.13.15.15.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2026 15:15:29 -0700 (PDT) Date: Mon, 13 Jul 2026 18:15:28 -0400 Message-ID: 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:20260713_1552/pstg-lib:20260713_1057/pstg-pwork:20260713_1552 From: Paul Moore To: Ian Bridges , Stephen Smalley , Ondrej Mosnacek , selinux@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-hardening@vger.kernel.org Subject: Re: [PATCH v2] selinux: replace strlcat() with seq_buf in selinux_ima_collect_state() References: In-Reply-To: On Jun 26, 2026 Ian Bridges wrote: > > In preparation for removing the deprecated strlcat() API[1], replace the > strscpy()/strlcat() chain in selinux_ima_collect_state() with a struct > seq_buf, which tracks the write position and remaining space internally. > > Each field is written with seq_buf_printf() using a "=%d;" format, which > removes the open-coded "=1;"/"=0;" constants. The seven per-append > WARN_ON(rc >= buf_len) truncation checks are replaced by a single > seq_buf_has_overflowed() check after the string is built. > > Link: https://github.com/KSPP/linux/issues/370 [1] > Signed-off-by: Ian Bridges > Reviewed-by: Stephen Smalley > --- > Changed in v2: replace the v1 seq_buf_puts() pairs with seq_buf_printf() > using a "=%d;" format, which drops the open-coded "=1;"/"=0;" constants. > > v1: https://lore.kernel.org/all/ajlN94VO7BYNUTAy@dev/ > > I didn't change the precomputation of the string size. An alternative, > which is used by other seq_buf callers (e.g. kernel/rcu/refscale.c, > mm/memcontrol.c), is to drop the precomputation and allocate an oversized > fixed buffer, relying on the seq_buf overflow check as a backstop. I'm > happy to rework the patch to adopt that alternative. Another option would be to split out the length calculation and only do it once at boot, e.g. call a selinux_ima_calculate_len() function from selinux_init(), and then reuse that length in selinux_ima_collect_state(). What you're doing here is no worse than what we currently have so I'm going to go ahead and merge it into selinux/dev, but if you could split out the length calculation I think that would be worthwhile. Thanks! > security/selinux/ima.c | 40 +++++++++++++--------------------------- > 1 file changed, 13 insertions(+), 27 deletions(-) -- paul-moore.com