From nobody Sat Feb 7 18:51:34 2026 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) (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 5883623E32B for ; Sun, 25 Jan 2026 21:01:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769374869; cv=none; b=nbjbo0Jgqbvxe9WbO6Mks/Scp++BrQdbTC7AtHewz64BPQgAYyoaQ1Vjv/Ci1rGXmLGn5FYj4mUEh1wuGUpOKcxdQu+u7rgNeO4qx0F7BNB+qwtVRnSo5dGEYT1m0JwLhiTsst1z7XoEA5TWtoNkj0woDjnu/RcuncTQGKKJNzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769374869; c=relaxed/simple; bh=KXzDsKBIBH7/Smgvq/uYgr7TFTUeTxZZkSerZHus/jE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=fLxUPL7usZEaPg4bPCwsxUPIkz4iDGE3YYQg+YCnhrWs5zR3MKDRClrO4LZ/3EyG21XZtQ890ClSxtUlgTqonCX101NvwpLDVKUav5tBbv4EJ0xH7/ZN2A+Pe6hPeF+lB0jfdzG5NxcJApW+qRdSsXwAO7wlGt+R4m0dBIEqaBM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Hp7w1qwh; arc=none smtp.client-ip=95.215.58.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Hp7w1qwh" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1769374865; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=AVVBNyZnoHuDoXjzcBcG8Nf+V8gmFPYyn44o12zOuzc=; b=Hp7w1qwhAvwM4pNqkz0uoI5hqJMnVSB6pV371kBkrBTMRHuF+8cw/l3xhWXQvh7dOItXCH rVAzH7qPxNk83EdndNCJEWpLKaRhc5bCIhUTf4j8wNDAlbsYhJW5/6FCLumPFRNrF3A3i0 5ZChAGFlEwZvumuQmbhvm1ywhgM6/T8= From: Thorsten Blum To: John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" Cc: Thorsten Blum , apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] apparmor: Replace memcpy + NUL termination with kmemdup_nul in do_setattr Date: Sun, 25 Jan 2026 22:00:15 +0100 Message-ID: <20260125210014.154432-2-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Use kmemdup_nul() to copy 'value' instead of using memcpy() followed by a manual NUL termination. No functional changes. Signed-off-by: Thorsten Blum --- security/apparmor/lsm.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index a87cd60ed206..98b92af5890e 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -866,12 +866,9 @@ static int do_setattr(u64 attr, void *value, size_t si= ze) =20 /* AppArmor requires that the buffer must be null terminated atm */ if (args[size - 1] !=3D '\0') { - /* null terminate */ - largs =3D args =3D kmalloc(size + 1, GFP_KERNEL); + largs =3D args =3D kmemdup_nul(value, size, GFP_KERNEL); if (!args) return -ENOMEM; - memcpy(args, value, size); - args[size] =3D '\0'; } =20 error =3D -EINVAL; --=20 Thorsten Blum GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4