Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp224262pxf; Wed, 17 Mar 2021 03:54:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPm+xWaO1UWJUNy8UH1eRaXDXJNvrJWixcQWI2g3Os7MYxilAfSaU4gNATFbtqA0SV0yzC X-Received: by 2002:aa7:dc15:: with SMTP id b21mr41214082edu.350.1615978450127; Wed, 17 Mar 2021 03:54:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615978450; cv=none; d=google.com; s=arc-20160816; b=hFrG42cDuHLWT9GHNIei3xU26PePVNDZLLLAiKDTM2jvwYMEy1YRNRjn/MZuVHZcFj qlCnxFK6X4sOrPAl2tg0KJpcv6+eE7+j/o1RLsnxdyxtiDRBE2bnwktacZ3KZaeJpLCH UPH4RziXNuOAios4PBN/Kc9CWi5iZIyzRuo+dVV3pjpnZKB/6+zYiBXHS65Cn3CzA4Eh aEnjINOXX6MgTDa0THkmULEFCzG3IJRtLq6Upzzgoyg3R+98qRjoanE34ynA+ZMakosr j9Iureh3ZF6TkkPUeR/ULErIJRDEVArg3/sBBLp/i0KCw7z7ZntKjr7b7GGDkdR7Ipbs 13lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Ql0XfQdaA6JFx0GO4CBbHqqpEsH/UmgUozlPO3OUoJU=; b=LTU3yUMbYoj3/qX3wjLtClk5kHM+O+OlPX/LQglmCSrEaf95xHg7xjUMqomW0kRy1/ cKqsENQMrfGSDn/oJku8KeeX6H6q1hrmHK/f8HT2/R7mOZDUiSpu8GjGpFK8bdinviq5 EwPnWcd3xQ5/rR1Ap/5n97yx80Fct8K5sXTkKACn50vrfUwmdWVArigNayqSZgkEmbee ZVE/1jeW20Ti3awFDGa9k/bTzPVbFSR4aMK2DCzhg22S1+dcsh1axOq1T8dZSZ7J6gMg bSz1+6qInne4YC+lJvgKO8/H3Hp4DgPk0Am/nr30YnDJEjMZSvlZ6a+wGB1dPa82RiKL hu+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jL4W4B2P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n19si15679773ejx.370.2021.03.17.03.53.46; Wed, 17 Mar 2021 03:54:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jL4W4B2P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231160AbhCQKuc (ORCPT + 99 others); Wed, 17 Mar 2021 06:50:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230389AbhCQKuW (ORCPT ); Wed, 17 Mar 2021 06:50:22 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA06EC06174A; Wed, 17 Mar 2021 03:50:14 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id gb6so901982pjb.0; Wed, 17 Mar 2021 03:50:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ql0XfQdaA6JFx0GO4CBbHqqpEsH/UmgUozlPO3OUoJU=; b=jL4W4B2PkQqNt97Y5GRGgsJ8AcescD8GHejesmsdeohePt3nyfdRPwmxYFwErT3CJP zAcKdlSvw0LslANUOnY/z1lY+XTmORNxCUwDTc0f64l5Y8BBj7VgAdkk6SWpLocXCxRc OXiNHJ+XN+oyqExkdwhKdvA7tvpUylNmfqvmaeMWFT11zbaX+qo7rx/YmISmf86g7pKC AMWk+EpqEuXukspVQ3IebJUmiy2hVEzF8wf0sqpBjhDH1fye3qBch0xcBX9BiGaZc1UX xowCrEYtMaer7bqbB6zHq5keYTSVY9ZWg13j/u3XGyDP7kR0tS797MbNWNx/C1YixpHf 4aUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ql0XfQdaA6JFx0GO4CBbHqqpEsH/UmgUozlPO3OUoJU=; b=mTqFQJbFA79MyD2V2J5HG0OL+o4oMMhfs19oxG9vuOVE02D0RhHttZjVjtYgwjT/PH o1ErM8kHP5b5N0ymc9/vrNrLPZMN/WBzHjwkyoPsqMs8XgqLsa8dhIy5uygs3mVASzQW 1Lr/Gxa4+PUA+lpjL/Jhd6sPHFnFNT/Vsto2cfw52f3tsUQEGJ8vmXspYBob0wPursQA 6OuETAa4zNrrVCJLgp5CsQmsfu8l7lDxWdJpHLVK2J4PiKDUFxDl+poJdaMXaDO2b2eI 7xZ4bELCu2syVpmK0S6oeGzN9W9LBdiEp16fTwbf+o6w2aOBeqdqEF3VMlLle579vEEi r9nw== X-Gm-Message-State: AOAM5339EdMrKzlT0LStxpGlCI/Cx0wNBVRiV0QM+tKbBjping2UgjMC sG28FiBSSYYeaxElfoPPKLY4E71B5rsI/Q== X-Received: by 2002:a17:90b:798:: with SMTP id l24mr3794372pjz.63.1615978214235; Wed, 17 Mar 2021 03:50:14 -0700 (PDT) Received: from localhost ([112.79.241.63]) by smtp.gmail.com with ESMTPSA id e8sm19237919pgb.35.2021.03.17.03.50.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 03:50:13 -0700 (PDT) From: Kumar Kartikeya Dwivedi To: ast@vger.kernel.org Cc: toke@redhat.com, Kumar Kartikeya Dwivedi , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] libbpf: use SOCK_CLOEXEC when opening the netlink socket Date: Wed, 17 Mar 2021 16:15:14 +0530 Message-Id: <20210317104512.4705-1-memxor@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Otherwise, there exists a small window between the opening and closing of the socket fd where it may leak into processes launched by some other thread. Signed-off-by: Kumar Kartikeya Dwivedi --- tools/lib/bpf/netlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/lib/bpf/netlink.c b/tools/lib/bpf/netlink.c index 4dd73de00..d2cb28e9e 100644 --- a/tools/lib/bpf/netlink.c +++ b/tools/lib/bpf/netlink.c @@ -40,7 +40,7 @@ static int libbpf_netlink_open(__u32 *nl_pid) memset(&sa, 0, sizeof(sa)); sa.nl_family = AF_NETLINK; - sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); + sock = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE); if (sock < 0) return -errno; -- 2.30.2