From patchwork Tue Mar 21 18:33:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mikhalitsyn X-Patchwork-Id: 13183053 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D6E8C6FD20 for ; Tue, 21 Mar 2023 18:45:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230408AbjCUSpk (ORCPT ); Tue, 21 Mar 2023 14:45:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230326AbjCUSpi (ORCPT ); Tue, 21 Mar 2023 14:45:38 -0400 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ECFB303C7 for ; Tue, 21 Mar 2023 11:45:36 -0700 (PDT) Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 0EB333F533 for ; Tue, 21 Mar 2023 18:45:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1679424333; bh=yvq6UMt9yN5iUlZuMyY0OG5lD/RxD6knn9gceCIGOkg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=HIPJQxMlM/Wv+lrL18I9c68nP4KtaXtCro/RU+uaaECc8R3DBz1wC8kLaGJqF/jXr tmVsFi4/6c4R7175sYqfYkla0ehDYwVFlj+V/I1tFYYzJIBfDVP+fHqkKNW9YPHYTA nfq1DpixlNc2rwdZgFQSbpddMkV6FSaBck7fsVQ1rqEdy+q5PCRNzzt2yns2ORMnQs RVQ14NiZk/L/iazpZu9HAVV+EVXIUJtsKue5MKkRBhtqn7j8IIdaWZo2D1ek4kTcrQ kFgszDVCK03s9zZVnkOIyJTjKtUFNg9AQH/MggKWDgiKFltebjk7VLJrfnXNQQ82UJ oFyWIQoIa1e/g== Received: by mail-ed1-f69.google.com with SMTP id i42-20020a0564020f2a00b004fd23c238beso23246246eda.0 for ; Tue, 21 Mar 2023 11:45:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679424332; 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=yvq6UMt9yN5iUlZuMyY0OG5lD/RxD6knn9gceCIGOkg=; b=ZMFoW/sN4GARCYhtQqORY5k8hv7MfPM+5cDli7DCeextgL+je6Lh0BjSEBAbWj0uhc p+5f16JmJGyYWSx51xqdn4YeeQa+cv145BiA36kWRqJX28T43QFjMRQRxmSVIRZs4VUx xMsi3lR6ujsGxBiRRUTdzHDSicRjzr1OYV1/mwsn7G+fIDC0QOgnM9rbvFgZKoswzFt7 fRzOAD0gdGVDI/xh53UfJBtZfxi4Rz2l77fFRLRymxhBu0FE2RomO8R7EwAq8CEHURjr bcw+ial+a+3j8EBZq7T6O58Ac1GW0FB5q882S3akzYOk5T8OShlVEUrJoVJWds+ciQoP Mebg== X-Gm-Message-State: AO0yUKXIBRNJrM0F1aYG+BGkjx6iZDJGRKDu/e/s6UFsfYuVTcl/VKgE NavLfMP+kYbcW0oqYilzeVPUQlCLwqKEpqi1ZfPWXS/T+MnPUzfR/CrWNPDhUdttApNnIJjPNFB jcYg58T/6avL4C/b4NWOxd+9kawR75S3+sA== X-Received: by 2002:a17:906:8476:b0:931:96c5:7646 with SMTP id hx22-20020a170906847600b0093196c57646mr3965073ejc.57.1679424332652; Tue, 21 Mar 2023 11:45:32 -0700 (PDT) X-Google-Smtp-Source: AK7set+h4AxTZC2eEvXbNStSrd7vEgU483k1w+wvWlNjFWtlvw+Tar3b0aYg/x+Y147Rd5JSOKP06g== X-Received: by 2002:a17:906:8476:b0:931:96c5:7646 with SMTP id hx22-20020a170906847600b0093196c57646mr3965041ejc.57.1679424332403; Tue, 21 Mar 2023 11:45:32 -0700 (PDT) Received: from amikhalitsyn.. (ip5f5bd076.dynamic.kabel-deutschland.de. [95.91.208.118]) by smtp.gmail.com with ESMTPSA id p9-20020a1709060e8900b0093313f4fc3csm4928194ejf.70.2023.03.21.11.45.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Mar 2023 11:45:31 -0700 (PDT) From: Alexander Mikhalitsyn To: davem@davemloft.net Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Alexander Mikhalitsyn , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Leon Romanovsky , David Ahern , Arnd Bergmann , Kees Cook , Christian Brauner , Kuniyuki Iwashima , Lennart Poettering Subject: [PATCH net-next v2 0/3] Add SCM_PIDFD and SO_PEERPIDFD Date: Tue, 21 Mar 2023 19:33:39 +0100 Message-Id: <20230321183342.617114-1-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 1. Implement SCM_PIDFD, a new type of CMSG type analogical to SCM_CREDENTIALS, but it contains pidfd instead of plain pid, which allows programmers not to care about PID reuse problem. 2. Add SO_PEERPIDFD which allows to get pidfd of peer socket holder pidfd. This thing is direct analog of SO_PEERCRED which allows to get plain PID. 3. Add SCM_PIDFD / SO_PEERPIDFD kselftest Idea comes from UAPI kernel group: https://uapi-group.org/kernel-features/ Big thanks to Christian Brauner and Lennart Poettering for productive discussions about this. Cc: "David S. Miller" Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni Cc: Leon Romanovsky Cc: David Ahern Cc: Arnd Bergmann Cc: Kees Cook Cc: Christian Brauner Cc: Kuniyuki Iwashima Cc: Lennart Poettering Alexander Mikhalitsyn (3): scm: add SO_PASSPIDFD and SCM_PIDFD net: core: add getsockopt SO_PEERPIDFD selftests: net: add SCM_PIDFD / SO_PEERPIDFD test arch/alpha/include/uapi/asm/socket.h | 3 + arch/mips/include/uapi/asm/socket.h | 3 + arch/parisc/include/uapi/asm/socket.h | 3 + arch/sparc/include/uapi/asm/socket.h | 3 + include/linux/net.h | 1 + include/linux/socket.h | 1 + include/net/scm.h | 14 +- include/uapi/asm-generic/socket.h | 3 + net/core/sock.c | 32 ++ net/mptcp/sockopt.c | 1 + net/unix/af_unix.c | 18 +- tools/include/uapi/asm-generic/socket.h | 3 + tools/testing/selftests/net/.gitignore | 1 + tools/testing/selftests/net/af_unix/Makefile | 3 +- .../testing/selftests/net/af_unix/scm_pidfd.c | 336 ++++++++++++++++++ 15 files changed, 417 insertions(+), 8 deletions(-) create mode 100644 tools/testing/selftests/net/af_unix/scm_pidfd.c