From patchwork Sun Apr 23 16:05:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 68186 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 93E28385700A for ; Sun, 23 Apr 2023 16:06:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 93E28385700A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682265976; bh=X++uT09e24oWUMFRffYiiNtQGqg3Ld1n4OnlJK/kB8w=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=oHtDUEhO6SWk+CoQ9R1MN4dhCTxIcS0YfHASGdGFud2IRF+2ag3SPNxaDOtrAnn/2 8OuGr7PsG6n7SUE6+zEJPQx13TiGe95xXuDLVPscwboUn13b3jw27t7e2/GbwiEino dKw9NbKbUjDmjeDjuIs0O+coGOb/ZaSAx1VLw2e0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by sourceware.org (Postfix) with ESMTPS id 577ED3858C50 for ; Sun, 23 Apr 2023 16:05:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 577ED3858C50 Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-4edc63c82d1so3572609e87.0 for ; Sun, 23 Apr 2023 09:05:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682265950; x=1684857950; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=X++uT09e24oWUMFRffYiiNtQGqg3Ld1n4OnlJK/kB8w=; b=kv+eq3XPbqmtNwnNgdsHcuVKAGJtgOqnZrkB6TSNLRQvuvXa2kF+u1y6YDV/cpjlM/ rteI+vjcFQDzHzCC4FiLDX525M6nvRmdVwVjwQwjo/QsziBM/scD43M2jH/XxyOrWN/j Zs6/BNEazimYk48gbRFHy+SWD6M/RDyIxQ7l82GzEp39N3/QZxi6yRhgt3iRgRfElG1P 9qsbaDEF84KZeEtNDbCcG6GX/IFQuaftwTSq3538FubksVYybxgXlAFR8c5I/tEZTcDB BeFfUK8jhUUHOLVcTk9/4byE9gYwbCxA1XN7HGpzLx0aKS0RskEQRGcA9qH8BPwWeuOy 9OBA== X-Gm-Message-State: AAQBX9ehKtR8vTPtn+2Cx2HvVCYcfITv6lZXF6jU5rYkVfJfUyyUlPKt c3XZpf2JGpqSchNHgJ6HTi++z7dLLMmlOQ== X-Google-Smtp-Source: AKy350bCRSxxzdvKXWXHb7MLoQdMGM/u081AIWdIjUJYp1+cBU4LAY2984yqbuknkLgoDZ+I7457eg== X-Received: by 2002:a19:c51a:0:b0:4e8:3f35:6844 with SMTP id w26-20020a19c51a000000b004e83f356844mr2625238lfe.19.1682265950184; Sun, 23 Apr 2023 09:05:50 -0700 (PDT) Received: from surface-pro-6.. ([2a00:1370:818c:4a57:e26d:6595:78ee:6d64]) by smtp.gmail.com with ESMTPSA id y20-20020a2e7d14000000b002a9ed7f6f90sm1411277ljc.73.2023.04.23.09.05.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Apr 2023 09:05:49 -0700 (PDT) To: libc-alpha@sourceware.org Cc: bug-hurd@gnu.org, Samuel Thibault Subject: [PATCH v2 1/4] hurd: Don't pass FD_CLOEXEC in CMSG_DATA Date: Sun, 23 Apr 2023 19:05:45 +0300 Message-Id: <20230423160548.126576-1-bugaevc@gmail.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, 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.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" It is of no concern to the receiving process whether or not the sender process wants to close its copy of sent file descriptor upon exec, and it should not influence whether or not the received file descriptor gets the FD_CLOEXEC flag set in the receiving process. The latter should in fact be dependent on the MSG_CMSG_CLOEXEC flag being passed to the recvmsg () call, which is going to be implemented in the following commit. Fixes 344e755248ce02c0f8d095d11cc49e340703d926 "hurd: Support sending file descriptors over Unix sockets" Signed-off-by: Sergey Bugaev --- sysdeps/mach/hurd/recvmsg.c | 5 +++-- sysdeps/mach/hurd/sendmsg.c | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/sysdeps/mach/hurd/recvmsg.c b/sysdeps/mach/hurd/recvmsg.c index 39de86f6..c08eb499 100644 --- a/sysdeps/mach/hurd/recvmsg.c +++ b/sysdeps/mach/hurd/recvmsg.c @@ -189,7 +189,8 @@ __libc_recvmsg (int fd, struct msghdr *message, int flags) if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) { /* SCM_RIGHTS support. */ - /* The fd's flags are passed in the control data. */ + /* The fd's flags are passed in the control data, but there currently + aren't any defined other than FD_CLOEXEC which we don't respect. */ int *fds = (int *) CMSG_DATA (cmsg); nfds = (cmsg->cmsg_len - CMSG_ALIGN (sizeof (struct cmsghdr))) / sizeof (int); @@ -200,7 +201,7 @@ __libc_recvmsg (int fd, struct msghdr *message, int flags) if (err) goto cleanup; fds[j] = opened_fds[newfds] = _hurd_intern_fd (newports[newfds], - fds[j], 0); + 0, 0); if (fds[j] == -1) { err = errno; diff --git a/sysdeps/mach/hurd/sendmsg.c b/sysdeps/mach/hurd/sendmsg.c index 5871d1d8..2f19797b 100644 --- a/sysdeps/mach/hurd/sendmsg.c +++ b/sysdeps/mach/hurd/sendmsg.c @@ -138,8 +138,11 @@ __libc_sendmsg (int fd, const struct msghdr *message, int flags) 0, 0, 0, 0); if (! err) nports++; - /* We pass the flags in the control data. */ - fds[i] = descriptor->flags; + /* We pass the file descriptor flags in the control data. + The only currently defined flag is FD_CLOEXEC, which we + don't want to pass and so we mask it out, so this will + always be 0 currently. */ + fds[i] = descriptor->flags & ~FD_CLOEXEC; err; }));