bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 06/15] kmsg: fix msg body alignment


From: Samuel Thibault
Subject: Re: [PATCH 06/15] kmsg: fix msg body alignment
Date: Sun, 28 Aug 2022 03:35:17 +0200
User-agent: NeoMutt/20170609 (1.8.3)

Luca Dariz, le mar. 28 juin 2022 12:10:45 +0200, a ecrit:
> * ipc/ipc_kmsg.c: align msg body to 4 bytes as done in mig
> 
> Signed-off-by: Luca Dariz <luca@orpolo.org>

Applied and fixed, thanks!

> ---
>  ipc/ipc_kmsg.c | 49 ++++++++++++++++++++++---------------------------
>  1 file changed, 22 insertions(+), 27 deletions(-)
> 
> diff --git a/ipc/ipc_kmsg.c b/ipc/ipc_kmsg.c
> index b9d29853..09801924 100644
> --- a/ipc/ipc_kmsg.c
> +++ b/ipc/ipc_kmsg.c
> @@ -68,9 +68,10 @@
>  #include <ipc/ipc_print.h>
>  #endif
>  
> -#define is_misaligned(x)     ( ((vm_offset_t)(x)) & (sizeof(vm_offset_t)-1) )
> -#define ptr_align(x) \
> -     ( ( ((vm_offset_t)(x)) + (sizeof(vm_offset_t)-1) ) & 
> ~(sizeof(vm_offset_t)-1) )
> +/* msg body is always aligned to 4 bytes */
> +#define msg_is_misaligned(x) ( ((vm_offset_t)(x)) & (sizeof(uint32_t)-1) )
> +#define msg_align(x) \
> +     ( ( ((vm_offset_t)(x)) + (sizeof(uint32_t)-1) ) & ~(sizeof(uint32_t)-1) 
> )
>  
>  ipc_kmsg_t ipc_kmsg_cache[NCPUS];
>  
> @@ -232,8 +233,8 @@ ipc_kmsg_clean_body(
>               if (((mach_msg_type_t*)type)->msgt_longform) {
>                       /* This must be aligned */
>                       if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
> -                         (is_misaligned(type))) {
> -                             saddr = ptr_align(saddr);
> +                         (msg_is_misaligned(type))) {
> +                             saddr = msg_align(saddr);
>                               continue;
>                       }
>                       name = type->msgtl_name;
> @@ -250,7 +251,7 @@ ipc_kmsg_clean_body(
>               /* padding (ptrs and ports) ? */
>               if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
>                   ((size >> 3) == sizeof(natural_t)))
> -                     saddr = ptr_align(saddr);
> +                     saddr = msg_align(saddr);
>  
>               /* calculate length of data in bytes, rounding up */
>  
> @@ -393,8 +394,8 @@ xxx:              type = (mach_msg_type_long_t *) eaddr;
>               if (((mach_msg_type_t*)type)->msgt_longform) {
>                       /* This must be aligned */
>                       if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
> -                         (is_misaligned(type))) {
> -                             eaddr = ptr_align(eaddr);
> +                         (msg_is_misaligned(type))) {
> +                             eaddr = msg_align(eaddr);
>                               goto xxx;
>                       }
>                       name = type->msgtl_name;
> @@ -411,7 +412,7 @@ xxx:              type = (mach_msg_type_long_t *) eaddr;
>               /* padding (ptrs and ports) ? */
>               if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
>                   ((size >> 3) == sizeof(natural_t)))
> -                     eaddr = ptr_align(eaddr);
> +                     eaddr = msg_align(eaddr);
>  
>               /* calculate length of data in bytes, rounding up */
>  
> @@ -1324,8 +1325,8 @@ ipc_kmsg_copyin_body(
>               if (longform) {
>                       /* This must be aligned */
>                       if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
> -                         (is_misaligned(type))) {
> -                             saddr = ptr_align(saddr);
> +                         (msg_is_misaligned(type))) {
> +                             saddr = msg_align(saddr);
>                               continue;
>                       }
>                       name = type->msgtl_name;
> @@ -1354,7 +1355,7 @@ ipc_kmsg_copyin_body(
>               /* padding (ptrs and ports) ? */
>               if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
>                   ((size >> 3) == sizeof(natural_t)))
> -                     saddr = ptr_align(saddr);
> +                     saddr = msg_align(saddr);
>  
>               /* calculate length of data in bytes, rounding up */
>  
> @@ -1376,9 +1377,6 @@ ipc_kmsg_copyin_body(
>               } else {
>                       vm_offset_t addr;
>  
> -                     if (sizeof(vm_offset_t) > sizeof(mach_msg_type_t))
> -                             saddr = ptr_align(saddr);
> -
>                       if ((eaddr - saddr) < sizeof(vm_offset_t)) {
>                               ipc_kmsg_clean_partial(kmsg, taddr, FALSE, 0);
>                               return MACH_SEND_MSG_TOO_SMALL;
> @@ -1591,8 +1589,8 @@ ipc_kmsg_copyin_from_kernel(ipc_kmsg_t kmsg)
>               if (longform) {
>                       /* This must be aligned */
>                       if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
> -                         (is_misaligned(type))) {
> -                             saddr = ptr_align(saddr);
> +                         (msg_is_misaligned(type))) {
> +                             saddr = msg_align(saddr);
>                               continue;
>                       }
>                       name = type->msgtl_name;
> @@ -1609,7 +1607,7 @@ ipc_kmsg_copyin_from_kernel(ipc_kmsg_t kmsg)
>               /* padding (ptrs and ports) ? */
>               if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
>                   ((size >> 3) == sizeof(natural_t)))
> -                     saddr = ptr_align(saddr);
> +                     saddr = msg_align(saddr);
>  
>               /* calculate length of data in bytes, rounding up */
>  
> @@ -2364,8 +2362,8 @@ ipc_kmsg_copyout_body(
>               if (longform) {
>                       /* This must be aligned */
>                       if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
> -                         (is_misaligned(type))) {
> -                             saddr = ptr_align(saddr);
> +                         (msg_is_misaligned(type))) {
> +                             saddr = msg_align(saddr);
>                               continue;
>                       }
>                       name = type->msgtl_name;
> @@ -2382,7 +2380,7 @@ ipc_kmsg_copyout_body(
>               /* padding (ptrs and ports) ? */
>               if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
>                   ((size >> 3) == sizeof(natural_t)))
> -                     saddr = ptr_align(saddr);
> +                     saddr = msg_align(saddr);
>  
>               /* calculate length of data in bytes, rounding up */
>  
> @@ -2426,9 +2424,6 @@ ipc_kmsg_copyout_body(
>               } else {
>                       vm_offset_t data;
>  
> -                     if (sizeof(vm_offset_t) > sizeof(mach_msg_type_t))
> -                             saddr = ptr_align(saddr);
> -
>                       data = * (vm_offset_t *) saddr;
>  
>                       /* copyout memory carried in the message */
> @@ -2795,8 +2790,8 @@ ipc_msg_print(mach_msg_header_t *msgh)
>               if (longform) {
>                       /* This must be aligned */
>                       if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
> -                         (is_misaligned(type))) {
> -                             saddr = ptr_align(saddr);
> +                         (msg_is_misaligned(type))) {
> +                             saddr = msg_align(saddr);
>                               continue;
>                       }
>                       name = type->msgtl_name;
> @@ -2841,7 +2836,7 @@ ipc_msg_print(mach_msg_header_t *msgh)
>               /* padding (ptrs and ports) ? */
>               if ((sizeof(natural_t) > sizeof(mach_msg_type_t)) &&
>                   ((size >> 3) == sizeof(natural_t)))
> -                     saddr = ptr_align(saddr);
> +                     saddr = msg_align(saddr);
>  
>               /* calculate length of data in bytes, rounding up */
>  
> -- 
> 2.30.2
> 
> 

-- 
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]