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 X-Patchwork-Id: 770871 Delivered-To: patch@linaro.org Received: by 2002:adf:9dca:0:b0:33b:4db1:f5b3 with SMTP id q10csp479302wre; Thu, 8 Feb 2024 10:48:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IF7+ji4/Cuznu5/mOCkkYLJ6ni+Fuvr33DwHvGS20jP9F/t1B/MrIodT7VklA5RXqpAhNXJ X-Received: by 2002:a05:622a:1486:b0:42c:3999:c9a5 with SMTP id t6-20020a05622a148600b0042c3999c9a5mr73785qtx.9.1707418118714; Thu, 08 Feb 2024 10:48:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707418118; cv=pass; d=google.com; s=arc-20160816; b=l9Zpj979rYfKC+NToPd0N51VOCL1NTz8pzhBv+8jr2kcFC9mjgsJjPaeWhIsd6OZtV 8TlKMWrc8W3eQBKyIenF8vYZtqXKtSU4MGiDjYcBCFHz1FZ5an9zkp6LUhjlHSLcaiU7 vidr+hqkLz0NjNbvreaGYcLMR2E05zepzL77QFVkOpiOtB0VfLv6ruIx+yychCc0gXWH FXZUKST2Mw1qre0WSypAgYCGMNNfQjMfNHVTm+56MHri9UZsqXy255cy6fOZA7lb9TSI ChKHLhCRftHG9/mWPxNamhVWJ3FvX9R3En+PMPDapV2on9UBY+0UBLUCsYRI5cKrKAZM b/pg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=+lXNyVmzS19qsCwprnU9lhxbiK68WYoELWDA1qhWWV0=; fh=H0+fXwY6hvpy3ZxLT8V0lNh/Wl5LPCnXR4XBWZYYGzw=; b=puIUz6Sqpel8RB4WhywfjEJCE1bzdktkYNy17SBfsjczgglyz85N4sQZoEevK/KQS1 mrdjIRuFE5q3L84aWh/PuBP+HWjMYnqUfsTT3+Jxcr/Mc/VMMmQERCfs3LHJ9TsAjRX8 et8hshxPrO4euN67e8HPzyxifW7/Q6II8jNbD1Bmq+gEHxudA4AAtc4lPtCJJJ3DX/4o lZyJiHrvNW3FazUF+A36fgbx/HfFBF8zS/L254shJiZgluW6V3YtMqS3zrNYuxU2UKHs ieWbp0e1utLBCiALl/+NQOhVnrPeFFDlvehNi1wiMZHL7HpIux1LJapcSUxIBIILNr4o Cksg==; darn=linaro.org ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="jrsh/h7W"; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org X-Forwarded-Encrypted: i=2; AJvYcCWqiCVOKGtFWBk0gUEZ5voSLgWFVEaeHPEPDp4tMIkHkF2wv6290p+i6V4UcN1HGPoSGF0Fi10qwP5oGM4yM3GM Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id 19-20020ac85913000000b0042beca41f7asi44673qty.397.2024.02.08.10.48.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 10:48:38 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="jrsh/h7W"; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3A8B13858010 for ; Thu, 8 Feb 2024 18:48:38 +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-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+patch=linaro.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