From patchwork Thu Feb 8 18:46:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 85480 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E172C385800B for ; Thu, 8 Feb 2024 18:48:50 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id 2CD89385840F for ; Thu, 8 Feb 2024 18:46:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2CD89385840F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2CD89385840F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::22f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707418009; cv=none; b=wmff7Gx/JqrBVm8mrLsWtQQbitMa1qMJcyfBYk422eNr4q8KIBotl8XSpZ4D2q6rwQtJvqPBKuTK81h4yvZttY+Bc4YFoZaz9aC9aYA8jiiMx/9Rxlt6kCeC83fwF8/PWLfmfcTvMwRKjZhfQjNbeFTkVVbGh4NN/fG2RN2dF+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707418009; c=relaxed/simple; bh=wNEfDapJnYnujUhCBMBO9HlIe30rH4wQGFMbqQzqlEE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=acTFhQLuQoYOyMXAo7WFjAaqbY8Fg5prsm1sDsRSoIyj8Ir3xr8DmtM178K8Hdl1rvB9km4NdISfEfkSWLQk3BzKV+VgO+gkAcPrJlhiRU1VjBJTZNTFQ7tAu3jodFnn4UT65aikOO1EM70aw8/71U/tb9jyIfz3De1IwDWwO1o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3bbbc6bcc78so39516b6e.1 for ; Thu, 08 Feb 2024 10:46:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1707418006; x=1708022806; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+lXNyVmzS19qsCwprnU9lhxbiK68WYoELWDA1qhWWV0=; b=jrsh/h7W6txqxna7SHShbEI3jKZC3oW5JS/LplcWdqxMjZTdLow8Q3fQyFxUgS47we RypO6YaVwx1FrBvqKxEGO1rozEx4SzKzUPDfObI9jVxFBiH8QKocmKOYg4/iHr0LkSPX SR2tv3sWhf8CC6WYVFgIkBksskvcrBe1bXqyW8TTuDzguxCzsKB3NKobqYXjgso1YJmz HssMb7n0fWwoG46eTJisww8TkOoxdw/NUpQLdLCxjBGRySxdGIyLXBktyqJKMqpaszbK wy7WGtBZD5U+ufO/FVtRR2RX1gPtXjvcg7Efb2KIuU5EGBJ2h53b179AoC9kPQyQHPdc dSmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707418006; x=1708022806; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+lXNyVmzS19qsCwprnU9lhxbiK68WYoELWDA1qhWWV0=; b=QbhiyeETzBVj2a6QFBP4nSLI3sbFeEBYuEiUTpG28MUI+HnVOoZMeLTz/nX6ZM7k2t cJGCxa5SdyW92EMyDSjcE4xfvKFUlKLJjyd4rsbw29gnaKvk4V3fUCYsrmj2d1N0SLJj U/OMO9hqV/1TNqrFUwXGdN5omxqVFl1z4e4jkaQt4PDzOyrUzyfO0DpyArjj/JNut0TD Y4M1m58Pd5b3zpEXBdoBvd1XUmD2xtEeUo6mp9SwAKCKftROqd66xwJ+ff4Qal3atQIA MmxEPRCcVgliPvKLVrpoDPJiR0xJnpyni5X3OQN2h7+oSmv3GFj/M4QS+06Zy7IC/2rg vvHg== X-Gm-Message-State: AOJu0YxTLJJVZ5ny95E4S47qK09ooCPvGZJbAdQbhmbnW/W2L0Kd50UQ KIuybdXkFnyJ5j60dZirlt8jMZtr9X8UwvBk7E6A2cOnjHZGOlt9DdBNXK38USJWPVK7lGkUnC8 z X-Google-Smtp-Source: AGHT+IHaMhg/pRInV+Pug6WZanZ18MxbalOZgIvu9t/YyeCjynwkLIaBk/RzN+aZvmlSZnizcs0QEw== X-Received: by 2002:a05:6359:4290:b0:178:950d:1175 with SMTP id kp16-20020a056359429000b00178950d1175mr14578rwb.13.1707418005968; Thu, 08 Feb 2024 10:46:45 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c0:378:6793:1dc3:1346:d6d6]) by smtp.gmail.com with ESMTPSA id n26-20020a638f1a000000b005d7994a08dcsm156408pgd.36.2024.02.08.10.46.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 10:46:45 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Siddhesh Poyarekar Subject: [PATCH v3 10/10] debug: Improve mqueue.h fortify warnings with clang Date: Thu, 8 Feb 2024 15:46:22 -0300 Message-Id: <20240208184622.332678-11-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208184622.332678-1-adhemerval.zanella@linaro.org> References: <20240208184622.332678-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org It improve mq_open. The compile and runtime checks have similar coverage as with GCC. Checked on aarch64, armhf, x86_64, and i686. Reviewed-by: Carlos O'Donell Tested-by: Carlos O'Donell --- rt/bits/mqueue2.h | 29 +++++++++++++++++++++++++++++ rt/mqueue.h | 3 +-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/rt/bits/mqueue2.h b/rt/bits/mqueue2.h index 0f9d67966f..d6d2d9012d 100644 --- a/rt/bits/mqueue2.h +++ b/rt/bits/mqueue2.h @@ -29,6 +29,8 @@ extern mqd_t __mq_open_2 (const char *__name, int __oflag) extern mqd_t __REDIRECT_NTH (__mq_open_alias, (const char *__name, int __oflag, ...), mq_open) __nonnull ((1)); + +#ifdef __va_arg_pack_len __errordecl (__mq_open_wrong_number_of_args, "mq_open can be called either with 2 or 4 arguments"); __errordecl (__mq_open_missing_mode_and_attr, @@ -55,3 +57,30 @@ __NTH (mq_open (const char *__name, int __oflag, ...)) return __mq_open_alias (__name, __oflag, __va_arg_pack ()); } +#elif __fortify_use_clang +__fortify_function_error_function __attribute_overloadable__ mqd_t +__NTH (mq_open (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)) + __fortify_clang_prefer_this_overload + __fortify_clang_error ((__oflag & O_CREAT), + "mq_open with O_CREAT in second argument needs 4 arguments") +{ + 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 diff --git a/rt/mqueue.h b/rt/mqueue.h index 787cc36df2..d39334ba16 100644 --- a/rt/mqueue.h +++ b/rt/mqueue.h @@ -110,8 +110,7 @@ extern int __REDIRECT (mq_timedsend, (mqd_t __mqdes, #endif /* Define some inlines helping to catch common problems. */ -#if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function \ - && defined __va_arg_pack_len +#if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function # include #endif