From nobody Sun Feb 8 04:12:04 2026 Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) (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 C418C320CCD for ; Mon, 19 Jan 2026 12:07:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768824422; cv=none; b=IXlQwSGv6i3nCKjcC2J4AedjOiglP3slfQuJ/uHFuix63H+FHKsRI7qAOPjfTfJ6hUpljfBxm11iEL3OXRECVyvyaaOobIjVdrhiNTpCjqBZbdFNTN9kt0BoLgE8qhnJpZ7hc+tAIHPBd9icvCHL2xkxelMSfAiHXDh/FxSCrTQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768824422; c=relaxed/simple; bh=DqVmoWgtjt0CHFg7yZpgFZbYkSMRd4nJfjJCwFUuI2Q=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=emMSdr5KwTd76zeWX1WmUTpGkNz6MT44jp0Zf1wzm0pRl3YsDU181HWqekvcAV3DtTCn+SipCTy34oHph62N1Xgpu+JBqInJE3UnM5Uk5Xjawvb9i/N50hgwi6DmnqQTfDXtAHsv8zlm3WSRSDN38OD4PHjRAMny55Sak4i7Dpg= 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=MNP7CqPg; arc=none smtp.client-ip=91.218.175.178 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="MNP7CqPg" 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=1768824418; 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=MNP7CqPgkwHTgcvdXUW641vM9d6rCYIu1TE2LSrBnc0nSwC4knedqA44Lu3PQPrhMAwyWp JyrFKtkgsJc3Ua74hPazj02Nr8Zna51nDkn8pj/Ky7ZsctuFX4GPkRQkCVoHf9nBdUs6oO yYT4kOjc1G+UzbjKoGmlbh2JQ5YC3mk= From: Thorsten Blum To: Tyler Hicks Cc: Thorsten Blum , ecryptfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] ecryptfs: Use struct_size to improve process_response + send_miscdev Date: Mon, 19 Jan 2026 13:05:51 +0100 Message-ID: <20260119120554.1243404-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 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