Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ecryptfs: Use struct_size to improve process_response + send_miscdev

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>
Signed-off-by: Tyler Hicks <code@tyhicks.com>

authored by

Thorsten Blum and committed by
Tyler Hicks
8b9bf58b f7a1c028

+7 -3
+2 -1
fs/ecryptfs/messaging.c
··· 6 6 * Author(s): Michael A. Halcrow <mhalcrow@us.ibm.com> 7 7 * Tyler Hicks <code@tyhicks.com> 8 8 */ 9 + #include <linux/overflow.h> 9 10 #include <linux/sched.h> 10 11 #include <linux/slab.h> 11 12 #include <linux/user_namespace.h> ··· 233 232 msg_ctx->counter, seq); 234 233 goto unlock; 235 234 } 236 - msg_size = (sizeof(*msg) + msg->data_len); 235 + msg_size = struct_size(msg, data, msg->data_len); 237 236 msg_ctx->msg = kmemdup(msg, msg_size, GFP_KERNEL); 238 237 if (!msg_ctx->msg) { 239 238 rc = -ENOMEM;
+5 -2
fs/ecryptfs/miscdev.c
··· 10 10 #include <linux/hash.h> 11 11 #include <linux/random.h> 12 12 #include <linux/miscdevice.h> 13 + #include <linux/overflow.h> 13 14 #include <linux/poll.h> 14 15 #include <linux/slab.h> 15 16 #include <linux/wait.h> ··· 149 148 u16 msg_flags, struct ecryptfs_daemon *daemon) 150 149 { 151 150 struct ecryptfs_message *msg; 151 + size_t msg_size; 152 152 153 - msg = kmalloc((sizeof(*msg) + data_size), GFP_KERNEL); 153 + msg_size = struct_size(msg, data, data_size); 154 + msg = kmalloc(msg_size, GFP_KERNEL); 154 155 if (!msg) 155 156 return -ENOMEM; 156 157 ··· 162 159 msg_ctx->msg->data_len = data_size; 163 160 msg_ctx->type = msg_type; 164 161 memcpy(msg_ctx->msg->data, data, data_size); 165 - msg_ctx->msg_size = (sizeof(*msg_ctx->msg) + data_size); 162 + msg_ctx->msg_size = msg_size; 166 163 list_add_tail(&msg_ctx->daemon_out_list, &daemon->msg_ctx_out_queue); 167 164 mutex_unlock(&msg_ctx->mux); 168 165