From: Thorsten Blum <thorsten.blum@linux.dev>
To: Tyler Hicks <code@tyhicks.com>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
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 [thread overview]
Message-ID: <20260205132456.1011140-1-thorsten.blum@linux.dev> (raw)
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 <thorsten.blum@linux.dev>
---
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 <mhalcrow@us.ibm.com>
* Tyler Hicks <code@tyhicks.com>
*/
+#include <linux/overflow.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/user_namespace.h>
@@ -232,7 +233,7 @@ int ecryptfs_process_response(struct ecryptfs_daemon *daemon,
msg_ctx->counter, seq);
goto unlock;
}
- msg_size = (sizeof(*msg) + msg->data_len);
+ msg_size = struct_size(msg, data, msg->data_len);
msg_ctx->msg = kmemdup(msg, msg_size, GFP_KERNEL);
if (!msg_ctx->msg) {
rc = -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 <linux/hash.h>
#include <linux/random.h>
#include <linux/miscdevice.h>
+#include <linux/overflow.h>
#include <linux/poll.h>
#include <linux/slab.h>
#include <linux/wait.h>
@@ -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;
- msg = kmalloc((sizeof(*msg) + data_size), GFP_KERNEL);
+ msg_size = struct_size(msg, data, data_size);
+ msg = kmalloc(msg_size, GFP_KERNEL);
if (!msg)
return -ENOMEM;
@@ -159,7 +162,7 @@ int ecryptfs_send_miscdev(char *data, size_t data_size,
msg_ctx->msg->data_len = data_size;
msg_ctx->type = msg_type;
memcpy(msg_ctx->msg->data, data, data_size);
- msg_ctx->msg_size = (sizeof(*msg_ctx->msg) + data_size);
+ msg_ctx->msg_size = msg_size;
list_add_tail(&msg_ctx->daemon_out_list, &daemon->msg_ctx_out_queue);
mutex_unlock(&msg_ctx->mux);
--
Thorsten Blum <thorsten.blum@linux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
next reply other threads:[~2026-02-05 13:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-05 13:24 Thorsten Blum [this message]
2026-03-26 5:01 ` [PATCH RESEND] ecryptfs: Use struct_size to improve process_response + send_miscdev Tyler Hicks
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260205132456.1011140-1-thorsten.blum@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=code@tyhicks.com \
--cc=ecryptfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox