Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp7022537pxv; Fri, 30 Jul 2021 08:13:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHtKxvaUGYzWxLoue1XZpeDo/9dWcmeftLngLb9XJnKDDcvRmBZI/PyX6BRZdHD91G4VfI X-Received: by 2002:a05:6402:881:: with SMTP id e1mr3632076edy.53.1627657999635; Fri, 30 Jul 2021 08:13:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627657999; cv=none; d=google.com; s=arc-20160816; b=CNfqM96QOltb3yyzQlVoT//zn4Nx7+ecJCtgusrBzbHZL7wuQnVkwL6YHmF7oY6Tr+ ocMP/w/A8klGN5kv1mR0FVloWUbzwyxdF0WW1VJnyrsd5Sp2MCvbcU19ya2bn5MbwBDC U8evm7Lt+yY5ZfEWGP41bzKjBrqhgYVrVrHXB22K3JwUOx0fbqhaYBthLV/gmNYpTHHq /rogx3InWStSLVcP3/7VyDEvcb+CkkmfWQ04qeSmN0N6OYIUGQwxcNPRAPRcNzannnsv /GyywmjJSx3jGgaCzK1sichReD+LhnXW6MKu99aB/oBlq0d0uvU7qQmJ7Dumpkfxh7p1 PqBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:message-id:user-agent :references:in-reply-to:subject:cc:to:from:date:mime-version :dkim-signature:dkim-signature; bh=PewmghU2Couc38HMuAXRIJRdxdZpqKISKEL9LkxlGXw=; b=spKxP2zwM+71BuBJOC6Nrlt+BXuIXFHPwxKErLu12OuzoSU3foWRWt0OADEbiYO5t+ J5WHr9kFnTg6sBQNHIxWp25JOeKnLXmmHK7icOUdpAbfqXASAO8eXHfyuu4prhNu6v29 XdDRue8Zca1jAjDwSYh5TUCXn3g6JJ48sihKBMMnc8wLIMeXx3mSiWKpP+EUg4rAWWG4 G25r5ydLQom3QewpcoKu5i0OBvOTn7eOuEFCtRRfxX/1yu9Er9MVzOT8Gvi78wcF6COs xgXf7v+71I4PT2BtaqWP/NhkNuP7XerZtueELRh8SRkbdKvaldR64Vrd0FfzcljNP8US b0rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=m32RFSN0; dkim=neutral (no key) header.i=@suse.de; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id wc16si1631875ejb.95.2021.07.30.08.12.55; Fri, 30 Jul 2021 08:13:19 -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=@suse.de header.s=susede2_rsa header.b=m32RFSN0; dkim=neutral (no key) header.i=@suse.de; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239369AbhG3PJj (ORCPT + 99 others); Fri, 30 Jul 2021 11:09:39 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:35928 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239030AbhG3PJi (ORCPT ); Fri, 30 Jul 2021 11:09:38 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 8022A20261; Fri, 30 Jul 2021 15:09:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1627657772; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PewmghU2Couc38HMuAXRIJRdxdZpqKISKEL9LkxlGXw=; b=m32RFSN03HsyR6LMfDu3cVlNl/piAvHbYqy6dEEKHRSZM9Z/CHN0unfaiRnO7UZ9UFzqSR WehhpA5Xo8eeE+TbS2yoms4YN0Clxc83rtKuu9fR7278hrqRq8HN4lyKhzZK7RxSIIkRp4 MUzGXfhxydGsS7qr+WbWoNkxcjcEi7o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1627657772; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PewmghU2Couc38HMuAXRIJRdxdZpqKISKEL9LkxlGXw=; b=w1VCpaNUUNiVdp3wJEdGoU2dSvIPf6chr7uoqFXucgj/ovNDLhhaREff7YYRjIggtl8tVF VBqWXpuFtHN74jDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6E0C413C32; Fri, 30 Jul 2021 15:09:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id SSpcGiwWBGFVHAAAMHmgww (envelope-from ); Fri, 30 Jul 2021 15:09:32 +0000 MIME-Version: 1.0 Date: Fri, 30 Jul 2021 08:09:32 -0700 From: Davidlohr Bueso To: cgel.zte@gmail.com Cc: keescook@chromium.org, christian.brauner@ubuntu.com, ktkhai@virtuozzo.com, jamorris@linux.microsoft.com, varad.gautam@suse.com, legion@kernel.org, linux-kernel@vger.kernel.org, Ran Xiaokai Subject: Re: [PATCH] ipc: add set_ownership() and permissions() callbacks for posix mqueue sysctl In-Reply-To: <20210729030651.536326-1-ran.xiaokai@zte.com.cn> References: <20210729030651.536326-1-ran.xiaokai@zte.com.cn> User-Agent: Roundcube Webmail Message-ID: <4b67a8df7823cc14ffb69657c82562b2@suse.de> X-Sender: dbueso@suse.de Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-07-28 20:06, cgel.zte@gmail.com wrote: > This patch adds a ctl_table_set per ipc namespace, and also the > set_ownership() and permissions() callbacks for the new ctl_table_root > for ipc mqueue syscgtls. ^^ sysctls This makes sense to me, just some nits below. Acked-by: Davidlohr Bueso > > Signed-off-by: Ran Xiaokai > --- ... > +static int set_permissions(struct ctl_table_header *head, > + struct ctl_table *table) > +{ > + struct ipc_namespace *ipc_ns = > + container_of(head->set, struct ipc_namespace, mq_set); > + struct user_namespace *user_ns = ipc_ns->user_ns; > + int mode; > + > + /* Allow users with CAP_SYS_RESOURCE unrestrained access */ > + if (ns_capable(user_ns, CAP_SYS_RESOURCE)) > + mode = (table->mode & S_IRWXU) >> 6; > + else > + /* Allow all others at most read-only access */ > + mode = table->mode & S_IROTH; Please use curly braces for the else. > + return (mode << 6) | (mode << 3) | mode; > +} > + > +static void set_ownership(struct ctl_table_header *head, > + struct ctl_table *table, > + kuid_t *uid, kgid_t *gid) > +{ > + struct ipc_namespace *ipc_ns = > + container_of(head->set, struct ipc_namespace, mq_set); > + struct user_namespace *user_ns = ipc_ns->user_ns; > + kuid_t ns_root_uid; > + kgid_t ns_root_gid; > + > + ns_root_uid = make_kuid(user_ns, 0); > + if (uid_valid(ns_root_uid)) > + *uid = ns_root_uid; > + > + ns_root_gid = make_kgid(user_ns, 0); > + if (gid_valid(ns_root_gid)) > + *gid = ns_root_gid; > +} Could set_permissions() and set_ownership() be factored such that we can avoid duplicated code between ipc and net ns? Something like: void set_permissions(struct ctl_table_header *head, struct ctl_table *table) { struct ipc_namespace *ipc_ns = container_of(head->set, struct ipc_namespace, mq_set); set_permissions_common(ipc_ns->user_ns); } Thanks, Davidlohr