Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp901392lqb; Fri, 15 Mar 2024 09:21:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU5bdB+8EOHIoNKisLkBnbItsqIcMMxwzA2vIWJarMT6d/7qcAzt8UavcW5f+bjxeSjRbY5xezGRd1Dv++y6koEJtsPzmfEGIE/qKXiyg== X-Google-Smtp-Source: AGHT+IFU/PjB67+KhRoYaJCCGnA3rtcZk3rkjJRIE8qTEJGYXH6c3gQV/WJr1MYO1gP9nfS5rE6a X-Received: by 2002:a05:6a00:4fc8:b0:6e5:adb9:b955 with SMTP id le8-20020a056a004fc800b006e5adb9b955mr4869696pfb.23.1710519717234; Fri, 15 Mar 2024 09:21:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710519717; cv=pass; d=google.com; s=arc-20160816; b=mECe6wzG1vxS59j0lVsVQ1l/MxtThz7qRQB/nnyDTXZ6I9g/AN2oYKmNK1v852B+SF i7pKC13ivpHQffkp7GOQ1TUrnN669Tm45R7uGUMHcSnsKziXspqGCsl/HrzXcDZsXJHk 7tNsiO8H67ITi90UorgB6fEHfIv3vscWlMpaJGOlF0PBaduasVvMoiCH9EvolDVKSgIM HCYt/kH+mldB5Eo0KiCVx5VCsO4h/Sy5+4dMOcmNDi2OLdmPO1Lt2lCMBbMB1T2PARNO CzmR7AfuyPRSYVdVAakRnVWYvii85GOChwEuEUxMQanEP7MvWHWwCxyZaefKbaabZOg5 tjmw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:message-id:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:date :from:dkim-signature; bh=7gHmLMXSc76YsEFNoHeZvBVNba0ZI3HR+IjjR/iYOa4=; fh=NYz8mFcTDqHV3Vl9baWOM5JV235hZcebZgbBo9oKe6w=; b=C3dA0R62m0gDytIROQrkGvui0EdXfMuow55vDBkA461m1QleDE7rwO06OSYUdqAF8b Wg1SDnp0VD+FSk6rRFOSslCbwWtXfnqaPQvb7o5l3CUjnkSVq/M6LE8/3bS/YaKijTwE IwypIJMqSTWwrZd2kvid36dZ2vui7iwEeHgKRLk46hnMbHFcHF2IYl9mhifDzBZmDQ3u 5BfEyjcsuUmI7yxGa1YMAlSZp5mM4jm8041tYepYHKBP8V0WWn0xMLBX19JQ6O8m13rp jyuvlRI8WIAPcBISIof3d2jmFRF4Qj9jn3LDWS2yUBCiEnjETU8AqBe2eaijycWDm5Y1 LMwQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b="Y/J0M5H6"; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-104622-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104622-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id x13-20020a056a000bcd00b006e07e72513csi3753686pfu.17.2024.03.15.09.21.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 09:21:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-104622-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b="Y/J0M5H6"; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-104622-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104622-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 5DDD3B22FB3 for ; Fri, 15 Mar 2024 16:20:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18B714596F; Fri, 15 Mar 2024 16:20:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="Y/J0M5H6" Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4708A3FE47; Fri, 15 Mar 2024 16:20:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710519640; cv=none; b=Msv6rNF992J1jOqsZuwQL6aYQ2IJXLpbmrj1mRU0AOOOZill+s1R7fnEDwgIBphy2ewskHRwgXltqkQWurtLD0tS4AGh2dHciTBtmkLthp78F/hAqhzY3ODLNFf8ECg90MwhfAq4Ew+MBj0Lux3LlAiQZ/ZYdaARw4+onIm78TY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710519640; c=relaxed/simple; bh=1n+G9SuhNWG59T4LbSXCZQEFL6hz0CIwSYG1SoowdRA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=Q6pkMw5n7gXeLR6k3sTIgutzKmOSN8xjcuE8LxCFmorcmqExCZlnWJQ92PXcyFq8SHutllkK8wR8FUpAelwP02indd/3HMbed1a3GBpnw1dRMJI+FgO2RY8JsUFBtEBHtDtSXWXfXbjMvW5gYvJ+xf2vUqWLx7f2YA7rTFcRP/w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=Y/J0M5H6; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1710519634; bh=1n+G9SuhNWG59T4LbSXCZQEFL6hz0CIwSYG1SoowdRA=; h=From:Date:Subject:To:Cc:From; b=Y/J0M5H6ecU85nrrQagfsKLxMsJ0OroPYVUzQcZSyfX5z3fLGAE2nKzL3QInaStF6 EEiFP4+uTA6WWG1q6hG94/9yX7OFU8ojrfxQIfIno2cdXdmWfWvScaGqAmkv/TySNJ +nLFncdAK0VvdJAulLNO+KwHRBfg7nN+7L4QlpPs= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Fri, 15 Mar 2024 17:20:31 +0100 Subject: [PATCH] net: always initialize sysctl ownership Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20240315-sysctl-net-ownership-v1-1-2b465555a292@weissschuh.net> X-B4-Tracking: v=1; b=H4sIAE519GUC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIxMDY0NT3eLK4uSSHN281BLd/PK81KLijMwC3aRkk1RD89TE1NREMyWg1oK i1LTMCrCx0bG1tQD3JL/EZgAAAA== To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Dmitry Torokhov , "Eric W. Biederman" Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Chamberlain , Joel Granados , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1710519633; l=1185; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=1n+G9SuhNWG59T4LbSXCZQEFL6hz0CIwSYG1SoowdRA=; b=VzGqNPpGHmW5VNKHjSGPj9uzf63W/DwkC2jy0ZtqKMFt+QnGxgmQBhctYl3eEEqa1pC7oIAOl Oxalw9/JZLxCNMwz8VJnIhENKZrFJqdZPFYH2C3BCgE/a/c9yElrEit X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The sysctl core does not initialize these fields when the set_ownership callback is present. So always do it in the callback. Fixes: e79c6a4fc923 ("net: make net namespace sysctls belong to container's owner") Signed-off-by: Thomas Weißschuh --- net/sysctl_net.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/net/sysctl_net.c b/net/sysctl_net.c index 051ed5f6fc93..03e320ddacc9 100644 --- a/net/sysctl_net.c +++ b/net/sysctl_net.c @@ -62,12 +62,10 @@ static void net_ctl_set_ownership(struct ctl_table_header *head, kgid_t ns_root_gid; ns_root_uid = make_kuid(net->user_ns, 0); - if (uid_valid(ns_root_uid)) - *uid = ns_root_uid; + *uid = uid_valid(ns_root_uid) ? ns_root_uid : GLOBAL_ROOT_UID; ns_root_gid = make_kgid(net->user_ns, 0); - if (gid_valid(ns_root_gid)) - *gid = ns_root_gid; + *gid = gid_valid(ns_root_gid) ? ns_root_gid : GLOBAL_ROOT_GID; } static struct ctl_table_root net_sysctl_root = { --- base-commit: e5eb28f6d1afebed4bb7d740a797d0390bd3a357 change-id: 20240315-sysctl-net-ownership-bc4e17eaeea6 Best regards, -- Thomas Weißschuh