@@ -243,7 +243,6 @@ ecryptfs_miscdev_read(struct file *file, char __user *buf, size_t count,
243
243
struct ecryptfs_daemon * daemon ;
244
244
struct ecryptfs_msg_ctx * msg_ctx ;
245
245
size_t packet_length_size ;
246
- u32 counter_nbo ;
247
246
char packet_length [3 ];
248
247
size_t i ;
249
248
size_t total_length ;
@@ -328,20 +327,18 @@ ecryptfs_miscdev_read(struct file *file, char __user *buf, size_t count,
328
327
"pending message\n" , __func__ , count , total_length );
329
328
goto out_unlock_msg_ctx ;
330
329
}
331
- i = 0 ;
332
- buf [i ++ ] = msg_ctx -> type ;
333
- counter_nbo = cpu_to_be32 (msg_ctx -> counter );
334
- memcpy (& buf [i ], (char * )& counter_nbo , 4 );
335
- i += 4 ;
330
+ rc = - EFAULT ;
331
+ if (put_user (msg_ctx -> type , buf ))
332
+ goto out_unlock_msg_ctx ;
333
+ if (put_user (cpu_to_be32 (msg_ctx -> counter ), (__be32 __user * )(buf + 1 )))
334
+ goto out_unlock_msg_ctx ;
335
+ i = 5 ;
336
336
if (msg_ctx -> msg ) {
337
- memcpy (& buf [i ], packet_length , packet_length_size );
337
+ if (copy_to_user (& buf [i ], packet_length , packet_length_size ))
338
+ goto out_unlock_msg_ctx ;
338
339
i += packet_length_size ;
339
- rc = copy_to_user (& buf [i ], msg_ctx -> msg , msg_ctx -> msg_size );
340
- if (rc ) {
341
- printk (KERN_ERR "%s: copy_to_user returned error "
342
- "[%d]\n" , __func__ , rc );
340
+ if (copy_to_user (& buf [i ], msg_ctx -> msg , msg_ctx -> msg_size ))
343
341
goto out_unlock_msg_ctx ;
344
- }
345
342
i += msg_ctx -> msg_size ;
346
343
}
347
344
rc = i ;
@@ -452,7 +449,8 @@ static ssize_t
452
449
ecryptfs_miscdev_write (struct file * file , const char __user * buf ,
453
450
size_t count , loff_t * ppos )
454
451
{
455
- u32 counter_nbo , seq ;
452
+ __be32 counter_nbo ;
453
+ u32 seq ;
456
454
size_t packet_size , packet_size_length , i ;
457
455
ssize_t sz = 0 ;
458
456
char * data ;
@@ -485,7 +483,7 @@ ecryptfs_miscdev_write(struct file *file, const char __user *buf,
485
483
count );
486
484
goto out_free ;
487
485
}
488
- memcpy (( char * ) & counter_nbo , & data [i ], 4 );
486
+ memcpy (& counter_nbo , & data [i ], 4 );
489
487
seq = be32_to_cpu (counter_nbo );
490
488
i += 4 ;
491
489
rc = ecryptfs_parse_packet_length (& data [i ], & packet_size ,
0 commit comments