From nobody Fri Apr 3 08:06:49 2026 Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) (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 9C9A137D130 for ; Mon, 9 Mar 2026 22:42:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773096157; cv=none; b=OtOpZXU5P4+5WQUq1LQAPWP+DI/mnnpzS14tx0EeQuuHjz0WauCUeSTeEdC1+Me1+XL32LkBQFglTJv51tTGb/Nyr+Ursi0dYfQqXc3Pg0Sd+4powEkxj7m4GJ4u7Iq7z4Z2w7AECNGAYIAcoA3FY3njKwpJ2fvcl1SRq+RYafI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773096157; c=relaxed/simple; bh=RUhFIUpE3q+j/RzplHM7utqXljK9ejAG8G3w/29/YpI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Ev58FgvIqdHkpA9Gzcu34ipOVWULlVY/58se3bguHLo/ZkI7Fej7CF9OvlPsLwfm4+ziJl5rHfdZ8n8+0p7daNaal+mEtKblsgp96WA9CeTiBUV+zr5YbRb/yAuy1xStsm5Wo33v8PkMwkythq81wRzWxPimajvCzRAgsh6g4VU= 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=Muuy1vri; arc=none smtp.client-ip=91.218.175.182 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="Muuy1vri" 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=1773096143; 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=IAPnfvwI82KtySwMtMOUp5GIZTs7KwYrmI4bhGYfZSk=; b=Muuy1vrixo8y5QksXCaOfruiWdUAxZA24ZTz586RjMAgE/aYQ2DeENfHqk6CJywQcaqy1y +dXS57MOVZ2D+nnu8996TtWlwObLKZZTqDCwiyg7zp4kus/CX3uDsAH3ssBeSS0n+UH1J4 lUSIVT1vc5DiWCzmJBiZUDMIU28BPfg= 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 RESEND] apparmor: Replace memcpy + NUL termination with kmemdup_nul in do_setattr Date: Mon, 9 Mar 2026 23:41:51 +0100 Message-ID: <20260309224150.84575-3-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=924; i=thorsten.blum@linux.dev; h=from:subject; bh=RUhFIUpE3q+j/RzplHM7utqXljK9ejAG8G3w/29/YpI=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDJnrfdbxOEyNqdm8JfnF5C+VSo2H8lIv/e+5HZgk0Lb4R gwzk4xHRykLgxgXg6yYIsuDWT9m+JbWVG4yidgJM4eVCWQIAxenAExE7RLDX8G9Gs19D2ecktmt cr/3lnDM83cnZuzKeBfSI5o1IUZsxSpGhmeBvfFXBJ9IaNzYLFRRLpD7fSnLg6UvlsctL5l64hX zaUYA X-Developer-Key: i=thorsten.blum@linux.dev; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 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. Reviewed-by: Serge Hallyn 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 c1d42fc72fdb..49aa6ad68838 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -858,12 +858,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;