diff mbox series

debug: Fix clang mq_open fortify wrapper (BZ 31917)

Message ID 20240621140841.2628624-1-adhemerval.zanella@linaro.org
State New
Headers show
Series debug: Fix clang mq_open fortify wrapper (BZ 31917) | expand

Commit Message

Adhemerval Zanella Netto June 21, 2024, 2:08 p.m. UTC
The mqueue.h fortify wrapper for clang added by c23107effbfe5300
is not fully correct, where correct 4 argument usage are not
being correctly handled.  For instance, while building socat 1.8
with a yocto clang based system shows:

  ./socat-1.8.0.0/xio-posixmq.c:119:8: error: 'mq_open' is unavailable: mq_open can be called either with 2 or 4 arguments
    119 |         mqd = mq_open(name, oflag, opt_mode, NULL);
        |               ^
  [...] /usr/include/bits/mqueue2.h:66:8: note: 'mq_open' has been explicitly marked unavailable here
     66 | __NTH (mq_open (const char *__name, int __oflag, mode_t mode,
        |        ^
  1 error generated.

The correct way to define the wrapper is to set invalid usage
with __fortify_clang_unavailable (for the case with 5 or more
arguments), followed by the expected ones.  This fix make mq_open
similar to current open wrappers.

[1] http://www.dest-unreach.org/socat/

Reported-by: Khem Raj <raj.khem@gmail.com>
---
 rt/bits/mqueue2.h | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

Comments

Khem Raj June 22, 2024, 5:23 a.m. UTC | #1
This works ok here with clang/main and failing cases are working fine.

Acked-by: Khem Raj <raj.khem@gmail.com>

On Fri, Jun 21, 2024 at 7:08 AM Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
>
> The mqueue.h fortify wrapper for clang added by c23107effbfe5300
> is not fully correct, where correct 4 argument usage are not
> being correctly handled.  For instance, while building socat 1.8
> with a yocto clang based system shows:
>
>   ./socat-1.8.0.0/xio-posixmq.c:119:8: error: 'mq_open' is unavailable: mq_open can be called either with 2 or 4 arguments
>     119 |         mqd = mq_open(name, oflag, opt_mode, NULL);
>         |               ^
>   [...] /usr/include/bits/mqueue2.h:66:8: note: 'mq_open' has been explicitly marked unavailable here
>      66 | __NTH (mq_open (const char *__name, int __oflag, mode_t mode,
>         |        ^
>   1 error generated.
>
> The correct way to define the wrapper is to set invalid usage
> with __fortify_clang_unavailable (for the case with 5 or more
> arguments), followed by the expected ones.  This fix make mq_open
> similar to current open wrappers.
>
> [1] http://www.dest-unreach.org/socat/
>
> Reported-by: Khem Raj <raj.khem@gmail.com>
> ---
>  rt/bits/mqueue2.h | 20 ++++++++------------
>  1 file changed, 8 insertions(+), 12 deletions(-)
>
> diff --git a/rt/bits/mqueue2.h b/rt/bits/mqueue2.h
> index d6d2d9012d..386404c0c8 100644
> --- a/rt/bits/mqueue2.h
> +++ b/rt/bits/mqueue2.h
> @@ -59,13 +59,16 @@ __NTH (mq_open (const char *__name, int __oflag, ...))
>  }
>  #elif __fortify_use_clang
>  __fortify_function_error_function __attribute_overloadable__ mqd_t
> -__NTH (mq_open (const char *__name, int __oflag, mode_t mode))
> +__NTH (mq_open (__fortify_clang_overload_arg (const char *, , __name),
> +               int __oflag, mode_t __mode, ...))
>       __fortify_clang_unavailable ("mq_open can be called either with 2 or 4 arguments");
>
> -__fortify_function_error_function __attribute_overloadable__ mqd_t
> -__NTH (mq_open (const char *__name, int __oflag, mode_t mode,
> -               struct mq_attr *attr, ...))
> -     __fortify_clang_unavailable ("mq_open can be called either with 2 or 4 arguments");
> +__fortify_function __attribute_overloadable__ mqd_t
> +__NTH (mq_open (__fortify_clang_overload_arg (const char *, ,__name),
> +               int __oflag, mode_t __mode, struct mq_attr *__attr))
> +{
> +  return __mq_open_alias (__name, __oflag, __mode, __attr);
> +}
>
>  __fortify_function __attribute_overloadable__ mqd_t
>  __NTH (mq_open (__fortify_clang_overload_arg (const char *, ,__name),
> @@ -76,11 +79,4 @@ __NTH (mq_open (__fortify_clang_overload_arg (const char *, ,__name),
>  {
>    return __mq_open_alias (__name, __oflag);
>  }
> -
> -__fortify_function __attribute_overloadable__ mqd_t
> -__NTH (mq_open (__fortify_clang_overload_arg (const char *, ,__name),
> -               int __oflag, int __mode, struct mq_attr *__attr))
> -{
> -  return __mq_open_alias (__name, __oflag, __mode, __attr);
> -}
>  #endif
> --
> 2.43.0
>
Adhemerval Zanella Netto June 27, 2024, 1:23 p.m. UTC | #2
On 22/06/24 02:23, Khem Raj wrote:
> This works ok here with clang/main and failing cases are working fine.
> 
> Acked-by: Khem Raj <raj.khem@gmail.com>

Thanks, if no one opposes it I will commit this shortly.

> 
> On Fri, Jun 21, 2024 at 7:08 AM Adhemerval Zanella
> <adhemerval.zanella@linaro.org> wrote:
>>
>> The mqueue.h fortify wrapper for clang added by c23107effbfe5300
>> is not fully correct, where correct 4 argument usage are not
>> being correctly handled.  For instance, while building socat 1.8
>> with a yocto clang based system shows:
>>
>>   ./socat-1.8.0.0/xio-posixmq.c:119:8: error: 'mq_open' is unavailable: mq_open can be called either with 2 or 4 arguments
>>     119 |         mqd = mq_open(name, oflag, opt_mode, NULL);
>>         |               ^
>>   [...] /usr/include/bits/mqueue2.h:66:8: note: 'mq_open' has been explicitly marked unavailable here
>>      66 | __NTH (mq_open (const char *__name, int __oflag, mode_t mode,
>>         |        ^
>>   1 error generated.
>>
>> The correct way to define the wrapper is to set invalid usage
>> with __fortify_clang_unavailable (for the case with 5 or more
>> arguments), followed by the expected ones.  This fix make mq_open
>> similar to current open wrappers.
>>
>> [1] http://www.dest-unreach.org/socat/
>>
>> Reported-by: Khem Raj <raj.khem@gmail.com>
>> ---
>>  rt/bits/mqueue2.h | 20 ++++++++------------
>>  1 file changed, 8 insertions(+), 12 deletions(-)
>>
>> diff --git a/rt/bits/mqueue2.h b/rt/bits/mqueue2.h
>> index d6d2d9012d..386404c0c8 100644
>> --- a/rt/bits/mqueue2.h
>> +++ b/rt/bits/mqueue2.h
>> @@ -59,13 +59,16 @@ __NTH (mq_open (const char *__name, int __oflag, ...))
>>  }
>>  #elif __fortify_use_clang
>>  __fortify_function_error_function __attribute_overloadable__ mqd_t
>> -__NTH (mq_open (const char *__name, int __oflag, mode_t mode))
>> +__NTH (mq_open (__fortify_clang_overload_arg (const char *, , __name),
>> +               int __oflag, mode_t __mode, ...))
>>       __fortify_clang_unavailable ("mq_open can be called either with 2 or 4 arguments");
>>
>> -__fortify_function_error_function __attribute_overloadable__ mqd_t
>> -__NTH (mq_open (const char *__name, int __oflag, mode_t mode,
>> -               struct mq_attr *attr, ...))
>> -     __fortify_clang_unavailable ("mq_open can be called either with 2 or 4 arguments");
>> +__fortify_function __attribute_overloadable__ mqd_t
>> +__NTH (mq_open (__fortify_clang_overload_arg (const char *, ,__name),
>> +               int __oflag, mode_t __mode, struct mq_attr *__attr))
>> +{
>> +  return __mq_open_alias (__name, __oflag, __mode, __attr);
>> +}
>>
>>  __fortify_function __attribute_overloadable__ mqd_t
>>  __NTH (mq_open (__fortify_clang_overload_arg (const char *, ,__name),
>> @@ -76,11 +79,4 @@ __NTH (mq_open (__fortify_clang_overload_arg (const char *, ,__name),
>>  {
>>    return __mq_open_alias (__name, __oflag);
>>  }
>> -
>> -__fortify_function __attribute_overloadable__ mqd_t
>> -__NTH (mq_open (__fortify_clang_overload_arg (const char *, ,__name),
>> -               int __oflag, int __mode, struct mq_attr *__attr))
>> -{
>> -  return __mq_open_alias (__name, __oflag, __mode, __attr);
>> -}
>>  #endif
>> --
>> 2.43.0
>>
diff mbox series

Patch

diff --git a/rt/bits/mqueue2.h b/rt/bits/mqueue2.h
index d6d2d9012d..386404c0c8 100644
--- a/rt/bits/mqueue2.h
+++ b/rt/bits/mqueue2.h
@@ -59,13 +59,16 @@  __NTH (mq_open (const char *__name, int __oflag, ...))
 }
 #elif __fortify_use_clang
 __fortify_function_error_function __attribute_overloadable__ mqd_t
-__NTH (mq_open (const char *__name, int __oflag, mode_t mode))
+__NTH (mq_open (__fortify_clang_overload_arg (const char *, , __name),
+		int __oflag, mode_t __mode, ...))
      __fortify_clang_unavailable ("mq_open can be called either with 2 or 4 arguments");
 
-__fortify_function_error_function __attribute_overloadable__ mqd_t
-__NTH (mq_open (const char *__name, int __oflag, mode_t mode,
-		struct mq_attr *attr, ...))
-     __fortify_clang_unavailable ("mq_open can be called either with 2 or 4 arguments");
+__fortify_function __attribute_overloadable__ mqd_t
+__NTH (mq_open (__fortify_clang_overload_arg (const char *, ,__name),
+		int __oflag, mode_t __mode, struct mq_attr *__attr))
+{
+  return __mq_open_alias (__name, __oflag, __mode, __attr);
+}
 
 __fortify_function __attribute_overloadable__ mqd_t
 __NTH (mq_open (__fortify_clang_overload_arg (const char *, ,__name),
@@ -76,11 +79,4 @@  __NTH (mq_open (__fortify_clang_overload_arg (const char *, ,__name),
 {
   return __mq_open_alias (__name, __oflag);
 }
-
-__fortify_function __attribute_overloadable__ mqd_t
-__NTH (mq_open (__fortify_clang_overload_arg (const char *, ,__name),
-		int __oflag, int __mode, struct mq_attr *__attr))
-{
-  return __mq_open_alias (__name, __oflag, __mode, __attr);
-}
 #endif