From nobody Sat Feb 7 10:07:58 2026 Received: from out-189.mta1.migadu.com (out-189.mta1.migadu.com [95.215.58.189]) (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 D1D1C3D668E for ; Thu, 5 Feb 2026 13:25:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770297921; cv=none; b=W7hidrbL5pT52Xp3CIkW3oHs3Zf+MIbzc2WZbtDobw9k4OrLqlTDqQ1HUvVA/sxwUcBi21Y32oOfLzu7xG+y+2ABuakxOEd5RS1USxICwbRKAEbEw6iPEaHvTTgIBGFqJALt3oC0GCa6ZtlScrMDybH9EXhF7xrRvFKA6ysgqCI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770297921; c=relaxed/simple; bh=DqVmoWgtjt0CHFg7yZpgFZbYkSMRd4nJfjJCwFUuI2Q=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ELPivcbRkIUjPM0/ogx/4mEICwOqaMi389XQ/kdBEBFAvWlmoLKWaWwQT7Y924jRL31Dvzv9RZMNPm1V0KU/3Qa9EtGjqvSYRFYqFlu0ZxGF5usgZIY8pJknoF/rF/7TLBPza7zXyU5rOPVqklXxzDfMe1ejM+m3wUIz0TIr254= 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=F2ePWrC/; arc=none smtp.client-ip=95.215.58.189 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="F2ePWrC/" 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=1770297909; 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=b2MBAWpGjsKDZu9eb6vGXhfLBF99PlZHXbi/O6SAQzw=; b=F2ePWrC/I3vqVuuBvFPC9X+CStsZiSi2v9hwBZXiTt2X9daSDKFkQ8A18hcVQiHg3nF7Ud k97l+dP1q78Smu9CYf+Z1NE7+OExfsVdU91Wxpt6SLonWRbC5ZCPrQau/zD2AmWf7ygBKE DCRYJKn4KeUYedkYuJO3qc9Jvk26r94= From: Thorsten Blum To: Tyler Hicks Cc: Thorsten Blum , ecryptfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RESEND] ecryptfs: Use struct_size to improve process_response + send_miscdev Date: Thu, 5 Feb 2026 14:24:51 +0100 Message-ID: <20260205132456.1011140-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" Use struct_size(), which provides additional compile-time checks for structures with flexible array members (e.g., __must_be_array()), to determine the allocation size for a new 'struct ecryptfs_message'. In send_miscdev(), reuse 'msg_size' instead of recalculating it. Signed-off-by: Thorsten Blum --- fs/ecryptfs/messaging.c | 3 ++- fs/ecryptfs/miscdev.c | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/ecryptfs/messaging.c b/fs/ecryptfs/messaging.c index 6318f3500e5c..c176d4a33ca2 100644 --- a/fs/ecryptfs/messaging.c +++ b/fs/ecryptfs/messaging.c @@ -6,6 +6,7 @@ * Author(s): Michael A. Halcrow * Tyler Hicks */ +#include #include #include #include @@ -232,7 +233,7 @@ int ecryptfs_process_response(struct ecryptfs_daemon *d= aemon, msg_ctx->counter, seq); goto unlock; } - msg_size =3D (sizeof(*msg) + msg->data_len); + msg_size =3D struct_size(msg, data, msg->data_len); msg_ctx->msg =3D kmemdup(msg, msg_size, GFP_KERNEL); if (!msg_ctx->msg) { rc =3D -ENOMEM; diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c index 4e62c3cef70f..5a7d08149922 100644 --- a/fs/ecryptfs/miscdev.c +++ b/fs/ecryptfs/miscdev.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -148,8 +149,10 @@ int ecryptfs_send_miscdev(char *data, size_t data_size, u16 msg_flags, struct ecryptfs_daemon *daemon) { struct ecryptfs_message *msg; + size_t msg_size; =20 - msg =3D kmalloc((sizeof(*msg) + data_size), GFP_KERNEL); + msg_size =3D struct_size(msg, data, data_size); + msg =3D kmalloc(msg_size, GFP_KERNEL); if (!msg) return -ENOMEM; =20 @@ -159,7 +162,7 @@ int ecryptfs_send_miscdev(char *data, size_t data_size, msg_ctx->msg->data_len =3D data_size; msg_ctx->type =3D msg_type; memcpy(msg_ctx->msg->data, data, data_size); - msg_ctx->msg_size =3D (sizeof(*msg_ctx->msg) + data_size); + msg_ctx->msg_size =3D msg_size; list_add_tail(&msg_ctx->daemon_out_list, &daemon->msg_ctx_out_queue); mutex_unlock(&msg_ctx->mux); =20 --=20 Thorsten Blum GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4