From patchwork Mon Jan 8 20:21:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 760784 Delivered-To: patch@linaro.org Received: by 2002:a5d:6e02:0:b0:337:62d3:c6d5 with SMTP id h2csp1062199wrz; Mon, 8 Jan 2024 12:23:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IEp3cvzJabEBzhd5sCfmi50/IqqUDDTLFbm83XF0tV5NPhwZi4Oqnkk0m7seENg7RGz7X8j X-Received: by 2002:ad4:5dea:0:b0:67f:adad:957e with SMTP id jn10-20020ad45dea000000b0067fadad957emr4605167qvb.131.1704745380557; Mon, 08 Jan 2024 12:23:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704745380; cv=pass; d=google.com; s=arc-20160816; b=j8/Mn70hBR7PyzNYRMF5jptXYk11JBK2Tpk1XSiojjL/AcyGtnKeFLkp6D8bfvVzi8 2Khho6xyJMRWgBJFuFaLBjNg0ltY7LPtdHx1EO+RE4O5hCMoIe+uFu4UYmQgB2X74nfI G0/KXCS852sAv2lP8DddFRHsSHFlVGRIIYtXZQ+KQwsBHjUmF7ydNzUj3J3ovKdzN+jm g727KBMBoyyks4fOmOxUkl780p0eWnQbFb1fAw4c0jVnx2mIJ9WkCBnzc5xiSkldMr6q 6Lc+M2Q1sonRA0EVcWqvUKPVTAOFFK/jMBr+vpsdE/GyDHsbtGREZPy/o1ZiIpYfWZPt SC1Q== 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=GgzVWNbxuGa9i5GiEZrgxNuLo7vlKaoDPYjJ99vA8jQ=; fh=dHLBnA+MhGtNtN2B2JMAELi4oD+gmgMg7DL8H0jYbkI=; b=Tp5UOA8AwkDLhqjIuYWkZrvbT9I6TYg/25ZFx5nBfZ/F/BBsoOyGJlmsiAZ9tLG85h A8oHhkb6PDts3XF/hWsBTTxpeIT/QC/NxmMdfcd28J45QhETKAS/MP7I0CK7OHnYOeut E8ewZ51IYU1/+C4pgMovccBh0PNnCIYXdRO2cNVq1L7f5ePNcYiWjPtlPI5ALXxIG0bf tl8pIVsdXYZoN/UWRbtZpL7m/5FazRzi2q0K804pQdJOd2fkobanl4B2metXfhZTMp/V C2gYYcLchXnCUoW9V7//G/G2KYVArMmc5AhReiQrrUUP0DHS+mLF4XKg4hJchC5wXjmQ Ta3A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pSuqS0LK; 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 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 c19-20020a0cca13000000b0067f61d6a5c9si682932qvk.440.2024.01.08.12.23.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 12:23:00 -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=pSuqS0LK; 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 C87D9385DC13 for ; Mon, 8 Jan 2024 20:22:59 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 3C05F3858417 for ; Mon, 8 Jan 2024 20:22:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C05F3858417 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 3C05F3858417 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::429 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704745328; cv=none; b=KQLFFUuUs9Nx78g6hD8g17dcj5mQ6u7U/o/O0crw9H9ncaE7hxlrI9aI6RJNSw7c5KliodWYLTXwGVqEmMD+5HP89UcmFsnF6H7p53z7KFKbuZB8gIoERkNaz2wUVRSb+q1jeOOCrLcse/inmYbyNSnFuD0c2StBy0O/8stx3to= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704745328; c=relaxed/simple; bh=okIx+NTh+eMK8CCevULhjvm3YeC/n1evLjmrFQUkvnQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=ac1JQUC8vmk5P7X4rTSB6oqqcxN+NW8G+RIm272r9KLC/FEplhUObTvrIKM/gwxW98PbyVkrCeWkiTW3CUKaXrRLaaoKhh9chNS4tA2XBA/8FYhGtm6vQvWncQRYnq2Cx53ntOvgcbtGeCPUzoMKlEZ6n01hwLpwBtb6Qo0MEUg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6db05618c1fso519359b3a.1 for ; Mon, 08 Jan 2024 12:22:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704745324; x=1705350124; 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=GgzVWNbxuGa9i5GiEZrgxNuLo7vlKaoDPYjJ99vA8jQ=; b=pSuqS0LKYcFtPXA/zOu8UL1SKB18Qw/PhiXQnojfZLnYRpS1BJrDa8pDQg3sQkLUJ2 iP9qRk7tfrgrwQwBhGc9bU+8Q1YXMqCHdbb4GDO4MnS/Hjw6YyHE8ELbDK1lKwecz5+M DUkkcYP9hp2BV82ypeZOFB8gOkpAltbn7jWVlgq39P2nP+YnfvLB25C4725QuyfebhP1 Te8mzA3PIp+P8yTep1vv6oKhxpmv0oCx7VBdvw/L/3ozWoN6KmWXgqAeyr6a4SFISP2s rdiUcEEFbG4wCK8mggfFkc09zi5Th8rQHGH1/3qM6P7uIVFLohlcGMwbC8QVGC8Br8Lb OIuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704745324; x=1705350124; 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=GgzVWNbxuGa9i5GiEZrgxNuLo7vlKaoDPYjJ99vA8jQ=; b=vKoOB+MhhojvzbD+I5K+4bEmn0RRiKjXukAIzk5L9IpCmKARt7QVoNOm7GLFiI2shK eulUNuXbBlOYCl6YTJZnnknjdTOvAna8P/BQqFfpeArd2/OjC4NMJ5mon9iyPjdp6x65 +mfjfexYhS9tf5nVXNUumsfVYjiJgTcRvJrNsM6GEWqtylcTMlEneBl5rg8i7vb6BVFh iswsD4/4TkopnWHiVllLZxLV9yGkCV6ZRd8tLEc0mFhvoGUwJLnMJXEpBDtS/bSz+rmP GASCl5Ic+2PchiffCcif6zrpd+gIVqFYV1P7cCJze9ylgGge6HE1tUCEXMCEJG54JWxb FCYg== X-Gm-Message-State: AOJu0YyThflkzwN/D6gCkTMHsRDRY2mx7q7bocsHW14ibCzZvqIoL9sK LFQqCHJccvHIujFvwfZNVQZ4JicsP6I+KbDrGtITEoY270o= X-Received: by 2002:aa7:938c:0:b0:6da:d8d5:bd4e with SMTP id t12-20020aa7938c000000b006dad8d5bd4emr4874000pfe.49.1704745324648; Mon, 08 Jan 2024 12:22:04 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:9dd2:7f25:c108:2fff:5f8e]) by smtp.gmail.com with ESMTPSA id z13-20020a62d10d000000b006d9bdc0f765sm287936pfg.53.2024.01.08.12.22.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 12:22:03 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 06/10] socket: Improve fortify with clang Date: Mon, 8 Jan 2024 17:21:45 -0300 Message-Id: <20240108202149.335305-7-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240108202149.335305-1-adhemerval.zanella@linaro.org> References: <20240108202149.335305-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 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 fortify checks recv, recvfrom, poll, and ppoll. The compile and runtime hecks have similar coverage as with GCC. Checked on aarch64, armhf, x86_64, and i686. --- io/bits/poll2.h | 29 +++++++++++++++++++++-------- socket/bits/socket2.h | 20 ++++++++++++++++---- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/io/bits/poll2.h b/io/bits/poll2.h index 6152a8c5e4..24ec1056eb 100644 --- a/io/bits/poll2.h +++ b/io/bits/poll2.h @@ -33,8 +33,13 @@ extern int __REDIRECT (__poll_chk_warn, (struct pollfd *__fds, nfds_t __nfds, __poll_chk) __warnattr ("poll called with fds buffer too small file nfds entries"); -__fortify_function __fortified_attr_access (__write_only__, 1, 2) int -poll (struct pollfd *__fds, nfds_t __nfds, int __timeout) +__fortify_function __fortified_attr_access (__write_only__, 1, 2) +__attribute_overloadable__ int +poll (__fortify_clang_overload_arg (struct pollfd *, ,__fds), nfds_t __nfds, + int __timeout) + __fortify_clang_warning_only_if_bos_lt2 (__nfds, __fds, sizeof (*__fds), + "poll called with fds buffer " + "too small file nfds entries") { return __glibc_fortify (poll, __nfds, sizeof (*__fds), __glibc_objsize (__fds), @@ -58,9 +63,13 @@ extern int __REDIRECT (__ppoll64_chk_warn, (struct pollfd *__fds, nfds_t __n, __ppoll64_chk) __warnattr ("ppoll called with fds buffer too small file nfds entries"); -__fortify_function __fortified_attr_access (__write_only__, 1, 2) int -ppoll (struct pollfd *__fds, nfds_t __nfds, const struct timespec *__timeout, - const __sigset_t *__ss) +__fortify_function __fortified_attr_access (__write_only__, 1, 2) +__attribute_overloadable__ int +ppoll (__fortify_clang_overload_arg (struct pollfd *, ,__fds), nfds_t __nfds, + const struct timespec *__timeout, const __sigset_t *__ss) + __fortify_clang_warning_only_if_bos_lt2 (__nfds, __fds, sizeof (*__fds), + "ppoll called with fds buffer " + "too small file nfds entries") { return __glibc_fortify (ppoll64, __nfds, sizeof (*__fds), __glibc_objsize (__fds), @@ -81,9 +90,13 @@ extern int __REDIRECT (__ppoll_chk_warn, (struct pollfd *__fds, nfds_t __nfds, __ppoll_chk) __warnattr ("ppoll called with fds buffer too small file nfds entries"); -__fortify_function __fortified_attr_access (__write_only__, 1, 2) int -ppoll (struct pollfd *__fds, nfds_t __nfds, const struct timespec *__timeout, - const __sigset_t *__ss) +__fortify_function __fortified_attr_access (__write_only__, 1, 2) +__attribute_overloadable__ int +ppoll (__fortify_clang_overload_arg (struct pollfd *, ,__fds), nfds_t __nfds, + const struct timespec *__timeout, const __sigset_t *__ss) + __fortify_clang_warning_only_if_bos_lt2 (__nfds, __fds, sizeof (*__fds), + "ppoll called with fds buffer " + "too small file nfds entries") { return __glibc_fortify (ppoll, __nfds, sizeof (*__fds), __glibc_objsize (__fds), diff --git a/socket/bits/socket2.h b/socket/bits/socket2.h index a88cb64370..04780f320e 100644 --- a/socket/bits/socket2.h +++ b/socket/bits/socket2.h @@ -30,14 +30,20 @@ extern ssize_t __REDIRECT (__recv_chk_warn, __warnattr ("recv called with bigger length than size of destination " "buffer"); -__fortify_function ssize_t -recv (int __fd, void *__buf, size_t __n, int __flags) +__fortify_function __attribute_overloadable__ ssize_t +recv (int __fd, __fortify_clang_overload_arg0 (void *, ,__buf), size_t __n, + int __flags) + __fortify_clang_warning_only_if_bos0_lt (__n, __buf, + "recv called with bigger length than " + "size of destination buffer") { size_t sz = __glibc_objsize0 (__buf); if (__glibc_safe_or_unknown_len (__n, sizeof (char), sz)) return __recv_alias (__fd, __buf, __n, __flags); +#if !__fortify_use_clang if (__glibc_unsafe_len (__n, sizeof (char), sz)) return __recv_chk_warn (__fd, __buf, __n, sz, __flags); +#endif return __recv_chk (__fd, __buf, __n, sz, __flags); } @@ -57,15 +63,21 @@ extern ssize_t __REDIRECT (__recvfrom_chk_warn, __warnattr ("recvfrom called with bigger length than size of " "destination buffer"); -__fortify_function ssize_t -recvfrom (int __fd, void *__restrict __buf, size_t __n, int __flags, +__fortify_function __attribute_overloadable__ ssize_t +recvfrom (int __fd, __fortify_clang_overload_arg0 (void *, __restrict, __buf), + size_t __n, int __flags, __SOCKADDR_ARG __addr, socklen_t *__restrict __addr_len) + __fortify_clang_warning_only_if_bos0_lt (__n, __buf, + "recvfrom called with bigger length " + "than size of destination buffer") { size_t sz = __glibc_objsize0 (__buf); if (__glibc_safe_or_unknown_len (__n, sizeof (char), sz)) return __recvfrom_alias (__fd, __buf, __n, __flags, __addr, __addr_len); +#if !__fortify_use_clang if (__glibc_unsafe_len (__n, sizeof (char), sz)) return __recvfrom_chk_warn (__fd, __buf, __n, sz, __flags, __addr, __addr_len); +#endif return __recvfrom_chk (__fd, __buf, __n, sz, __flags, __addr, __addr_len); }