From patchwork Thu Dec 21 18:59:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 757041 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp1055680wrw; Thu, 21 Dec 2023 11:02:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGFUzebVFOF97kVkVG8idgnGEZCxClrZdxrHZT0TG8jOYBVpLmpBbtAPmpjL0pqccMDtxq7 X-Received: by 2002:a05:6808:199e:b0:3af:9838:8494 with SMTP id bj30-20020a056808199e00b003af98388494mr201889oib.20.1703185354203; Thu, 21 Dec 2023 11:02:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1703185354; cv=pass; d=google.com; s=arc-20160816; b=mN5mLHO2hCTCKFZfCq9UfTS1/BtO2x/xfuiOwfjVabGG7eRUj6FCGk+jDFIvK56gRK REYFMuzXAOr9NYacGyxA0K991FklHezGoqQzPMQZjEwI+VB9JEE1b9YZJaJ7td1Zp0kr SKXF/a///TmtPO6n0pm9m83UHKOr8SHS6qLZoy7mZYAzoAhDUz8f0daSvkdz8qN2JZiS 51bdH8mELpWoFRxqghSnRDVnQpYVpAUeLeDb/k+6tfRRLKowCgEEspj+eHoNiLiz5eM6 qn2NoyFesQeSnCVVjV+lwNq5jMDjdOS9EIhMDy9FMAeX/6I3cWZy4AvLna5D93/a/OFz cg9A== 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:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=zJ1WEfBX7wXWDN/2IZ2D/88qLBvsCBl84PYhuvSQEU0=; fh=JNN3k7BRNI1OnWdIBK9jlpNeitGd8uBm02dHI75AGcg=; b=OsjAh7NinWvQA7gDnE07pY8Ts5xQtAN+wdEWn+0tRDq593ttPL19WULEiDt+2/7EJ1 4noncrfZ4suk4eFZz25d1tT7nRpzE1M7dfnsiXWL4wxPvYuyvwgZI/hbmGhtb0bYTZEW kqKqU8f+GTcm5894P2KEKSM8nr97tVyKm52vvzrhmurgad3bDfFzfKIrUEY8+jCphl8d vT5y+Qg/TRbtPeRacZmclzy5ynBf2smXN9H/26e+KmSazXMhOZVCieln+hvh4mkbGf40 6WqNcn7Q/53/HhNyOCqMA3EKSbM1gJLbrNYyEzUeMcSNNn+JsNvh7oA9J2sWiXi0daT8 mWiA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Rf4V05pl; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 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 Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hp15-20020a0561022a6f00b00466a2bbcb33si473690vsb.766.2023.12.21.11.02.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 11:02:34 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Rf4V05pl; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 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 5F4633882078 for ; Thu, 21 Dec 2023 19:02:25 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x2c.google.com (mail-oa1-x2c.google.com [IPv6:2001:4860:4864:20::2c]) by sourceware.org (Postfix) with ESMTPS id 44931386483A for ; Thu, 21 Dec 2023 19:00:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 44931386483A 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 44931386483A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4860:4864:20::2c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703185213; cv=none; b=hXSIRQieZc/rZks7JAT+g1oLwbPbqNVgIlOmAcQcDQMQM6lICufhBfNENBHx2tHQDwpT4UsKefHdY0CCMVAwsf1VCY/BL1sQIziiDLK562FRH0CgvbTr16bzpZmW8Pi3YmCOJVH22pQdDdKp5Dzu4PlOVNl4F7XRyTsehGV7Lx8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703185213; c=relaxed/simple; bh=lUM9r+i9ii24+v8dqFii9sEBtWAGGbQhqJsHzmzNfJ0=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Hs3DRmbv3DEAuG2Rnkt92jGCI+J1iNBrUnxlhHCnCLzoa1pZKmBhcjI5kNg7QFfVzxnh9G37uRrQrJ6NB1A57sD7EyrsQKDlh4rjR25BcwN3NA1qlWrx2e8pi2gx0o34paAEos8XxOMDEGZbOoVTYJSg3tHiotj8fXqw2FPGRVA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-2041064831bso757887fac.3 for ; Thu, 21 Dec 2023 11:00:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703185211; x=1703790011; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=zJ1WEfBX7wXWDN/2IZ2D/88qLBvsCBl84PYhuvSQEU0=; b=Rf4V05plTOA3LbU/552iWs00hcoPEeirnYGeY13MBFnrMY3FT/lK0gdzN6UL3oho66 t2YIDOhDSaTxdQd0O5aRhSU0p063gkVDZizz2NDdgprknSOavIerr306mNgnCCE3p/40 yW0ydRiWPFk+2Z5DUFZYikJWVVaseJeQaTjXyz93J45Hhg1ElgKD3Zmpbs9pC5F/09UV dBSVY1d/3yX1a32u+++HoCOG7kyTbkZKFexhFPi2IlaI7aDmDtGqvgCVtce3VebWlizn Wx4NWGja7R3OcIaFeAbHsIpHfJZzbtv2iMOMn/DHtfTVq0DLx2pAUi1u/3JthW2oPmvI rG1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703185211; x=1703790011; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zJ1WEfBX7wXWDN/2IZ2D/88qLBvsCBl84PYhuvSQEU0=; b=Yw1SASsSF75tyK/29AXQrLapbJxVy+LczWK/TJeYZAyXZU2SIy/+LA6s9D7kosCe1F reZv1xY3F4WDz1M7iUluAEfvGrbk+EoxmybAbzxgoN3neQ5NOMRptWLGcEvFkSQDpiB+ uCH+15UxAVAg7Rt7/ggkwm5U304I7c41DCyB7m/WZcqOxwHSyZkAqDyGmJnyKc7QWrkz zWaRE2VB7/j9TSN5P6r4Ey+W5dEq+EF983foG4+va3rWidxC4yDdFYz6OpWIdU0U4lUI dFaSsrIdwZtGckDTvV0/gui8I2PMcpczOwzSsBtIqd+p/BlGqZtQOmTKIaal2NEeqUMt uYRA== X-Gm-Message-State: AOJu0Ywjt2GwLxqEuRd3AWk6/PSPZJK73rNzipABTVkm5wKB4yw2oJWo QmfIWb+ZF6P6gN1nbmzlqjvFL0LIx7KieCdGfz4KyL+Uf8o= X-Received: by 2002:a05:6870:7191:b0:204:1347:4775 with SMTP id d17-20020a056870719100b0020413474775mr252794oah.72.1703185210957; Thu, 21 Dec 2023 11:00:10 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c0:8192:ecd7:d327:bea0:14dc]) by smtp.gmail.com with ESMTPSA id a9-20020a63e409000000b005cdbebd61d8sm1946165pgi.9.2023.12.21.11.00.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 11:00:10 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Siddhesh Poyarekar Subject: [PATCH 15/15] debug: Improve mqueue.h fortify warnings with clang Date: Thu, 21 Dec 2023 15:59:29 -0300 Message-Id: <20231221185929.1307116-16-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221185929.1307116-1-adhemerval.zanella@linaro.org> References: <20231221185929.1307116-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 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. --- 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 c1d86662dc..69897fd578 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 126a6b54b3..9279763841 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