From nobody Thu Oct 2 09:16:51 2025 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) (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 49B4B60B8A for ; Thu, 18 Sep 2025 15:08:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758208116; cv=none; b=gTGa1URMcbm+posZ40+mvf8EI/bUpcapxxcQ696YzNbwbSsI6q5vKnZXzfSnbwO0BHivJ/7CpNSuOSMmK4rpqvgao/xWFHzX+B92ZZZJDb8Iia7Tmyf/zqAsirXRbi8gUWaZl3uQD7yzLw652zMKpiou9+okD5KlcoN+lDcePRc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758208116; c=relaxed/simple; bh=OH1cXWh/ceZm2s0pVVZvR2aSkoX+P8HmZ4spkodV/Ew=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=sxIVa+Gz1zxyZ0KEHkgEz2Jtu1j2dzQMRRqNRYsdEoU3Anmw0A+zhaE2EsifGfu/bKJk6dnTndhy4xCY9CPMXCE8OxKsnGgdERYCzYN/CJ50IhF4KODHx1zFM5KKLncCsXnIS+XG+pecvuTeUg+Gykn5+a8NP9UvWjaRz1O8nec= 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=mYnmGYrC; arc=none smtp.client-ip=91.218.175.185 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="mYnmGYrC" 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=1758208111; 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=Bt8ipHYIkaJJgEvMQ5h6jOk88qp19PNj3om5XuureRA=; b=mYnmGYrC1K2UGVSpmP7Bo6zNS4ZiGU28CCHwSPuW5eOyLSdMlT8+fkPx2RSQbIAxq+R8Hb LbREZOaK5H791nb67+RjrtcFFx74Q/oj4xUV+zAahRJZgEQgGbtxTO2HCwj+r18Ylzma65 9uG8zhVnXAoXbTx6vF6yNQvpEZKYhCE= From: Thorsten Blum To: Mike Marshall , Martin Brandenburg Cc: Thorsten Blum , devel@lists.orangefs.org, linux-kernel@vger.kernel.org Subject: [PATCH] fs/orangefs: Replace kzalloc + copy_from_user with memdup_user_nul Date: Thu, 18 Sep 2025 17:08:10 +0200 Message-ID: <20250918150811.259596-1-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" Replace kzalloc() followed by copy_from_user() with memdup_user_nul() to simplify and improve orangefs_debug_write(). Allocate only 'count' bytes instead of the maximum size ORANGEFS_MAX_DEBUG_STRING_LEN, and set 'buf' to NULL to ensure kfree(buf) still works. No functional changes intended. Signed-off-by: Thorsten Blum --- fs/orangefs/orangefs-debugfs.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/fs/orangefs/orangefs-debugfs.c b/fs/orangefs/orangefs-debugfs.c index 1c375fb65018..79267b3419f2 100644 --- a/fs/orangefs/orangefs-debugfs.c +++ b/fs/orangefs/orangefs-debugfs.c @@ -440,14 +440,13 @@ static ssize_t orangefs_debug_write(struct file *file, count =3D ORANGEFS_MAX_DEBUG_STRING_LEN; } =20 - buf =3D kzalloc(ORANGEFS_MAX_DEBUG_STRING_LEN, GFP_KERNEL); - if (!buf) - goto out; - - if (copy_from_user(buf, ubuf, count - 1)) { + buf =3D memdup_user_nul(ubuf, count - 1); + if (IS_ERR(buf)) { gossip_debug(GOSSIP_DEBUGFS_DEBUG, - "%s: copy_from_user failed!\n", + "%s: memdup_user_nul failed!\n", __func__); + rc =3D PTR_ERR(buf); + buf =3D NULL; goto out; } =20 --=20 2.51.0