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 Netto X-Patchwork-Id: 1879417 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Rf4V05pl; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sx0Db0d7pz1ydZ for ; Fri, 22 Dec 2023 06:02:39 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 446283884510 for ; Thu, 21 Dec 2023 19:02:28 +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-Google-Smtp-Source: AGHT+IFFgXUfi6SvdPljjw2zpA7IlrPI80KXgz4OSEOuR95hUblNhP2lsoqTtQLoR13qw9g6974cIg== 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+incoming=patchwork.ozlabs.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