linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luca Barbieri <ldb@ldb.ods.org>
To: trond.myklebust@fys.uio.no
Cc: Linus Torvalds <torvalds@transmeta.com>,
	Linux FSdevel <linux-fsdevel@vger.kernel.org>,
	Linux Kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] Initial support for struct vfs_cred   [0/1]
Date: 01 Sep 2002 01:13:55 +0200	[thread overview]
Message-ID: <1030835635.1422.39.camel@ldb> (raw)
In-Reply-To: <15729.17279.474307.914587@charged.uio.no>

[-- Attachment #1: Type: text/plain, Size: 3512 bytes --]

On Sun, 2002-09-01 at 00:30, Trond Myklebust wrote:
> >>>>> " " == Luca Barbieri <ldb@ldb.ods.org> writes:
> 
>      > Then the rest of the code doesn't need to know at all that
>      > credentials are shared and is simpler and faster.  We have
>      > however a larger penalty on credential change but, as you say,
>      > that's extremely rare (well, perhaps not necessarily extremely,
>      > but still rare).
> 
> What if I, in a fit of madness/perversion, decide to use CLONE_CRED
> between 2 kernel threads (i.e. no 'kernel entry')?
You don't or you manually patch the task_struct of the other threads.
This isn't a serious concern.

> Leaving CLONE_CRED aside, please do not forget that most of the
> motivation for vfs_cred is the need to *cache* credentials.
> This is something which we already do today in several filesystems:
> Coda, Intermezzo, NFS, to name but the most obvious.
> The result of the lack of a VFS-sanctioned credential is that we have
> to use 'struct file' as a vehicle for passing credentials in, for
> instance, the address_space_operations, and that each filesystem ends
> up having to keep its own private copies of those credentials in
> file->private_data.
I'm not proposing to not use vfs_cred (the pseudocode I written includes
it).
I'm just suggesting a way to speed up access to credentials.
Your code does get_current_vfscred()/put_vfscred() in normal paths and
accesses credentials with an indirect pointer.
Furthermore, setting the uid and gid are very expensive since they need
to break copy-on-write.
If we instead only allow changes to credentials on kernel mode entry, we
don't have to worry about changing credentials and the code becomes
simpler and faster.
It also seems better to only copy-on-write groups and just copy uid and
gid.


For example, rather than this;
-               uid_t saved_fsuid = current->fsuid;
+               struct vfs_cred *saved_cred = get_current_vfscred();
                kernel_cap_t saved_cap = current->cap_effective;
 
                /* Create RPC socket as root user so we get a priv port
*/
-               current->fsuid = 0;
+               setfsuid(0);
                cap_raise (current->cap_effective,
CAP_NET_BIND_SERVICE);
                xprt = xprt_create_proto(host->h_proto, &host->h_addr,
NULL);
-               current->fsuid = saved_fsuid;
+               set_current_vfscred(saved_cred);
+               put_vfscred(saved_cred);

you can just do this:
-               uid_t saved_fsuid = current->fsuid;
+               uid_t saved_fsuid = current->fscred.uid;
                kernel_cap_t saved_cap = current->cap_effective;
 
                /* Create RPC socket as root user so we get a priv port
*/
-               current->fsuid = 0;
+               current->fscred.uid = 0;
                cap_raise (current->cap_effective,
CAP_NET_BIND_SERVICE);
                xprt = xprt_create_proto(host->h_proto, &host->h_addr,
NULL);
-               current->fsuid = saved_fsuid;
+               current->fscred.uid = saved_fsuid;

(here the fscred is the one called cred in the pseudocode: fscred is a
better name).

This code uses vfs_cred but is as fast as the old one while the one in
your patch is significantly slower (e.g. compare your setfsuid with
current->fscred.uid = xxx).
If you then need to keep the vfs_cred data for longer than a single
syscall, just copy it like you would do in the propagation code.
That means copying the structure and then incrementing the reference
count on groups.


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

  reply	other threads:[~2002-08-31 23:13 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1030820234.4408.119.camel@ldb>
2002-08-31 19:36 ` [PATCH] Initial support for struct vfs_cred [0/1] Linus Torvalds
2002-08-31 19:38   ` Luca Barbieri
2002-08-31 22:30     ` Trond Myklebust
2002-08-31 23:13       ` Luca Barbieri [this message]
2002-09-01 13:03         ` Trond Myklebust
2002-09-01 14:10           ` Trond Myklebust
2002-09-01 14:20             ` Luca Barbieri
     [not found]             ` <1030890022.2145.52.camel@ldb>
2002-09-01 16:40               ` Trond Myklebust
     [not found]               ` <15730.17171.162970.367575@charged.uio.no>
2002-09-01 18:54                 ` Luca Barbieri
2002-09-01 19:40                   ` Trond Myklebust
     [not found]                   ` <15730.27952.29723.552617@charged.uio.no>
2002-09-01 21:34                     ` Luca Barbieri
     [not found]                     ` <1030916061.2145.344.camel@ldb>
2002-09-01 21:56                       ` Trond Myklebust
     [not found]                       ` <15730.36080.987645.452664@charged.uio.no>
2002-09-01 22:50                         ` Luca Barbieri
2002-09-01 14:33           ` Luca Barbieri
2002-09-01 16:38             ` Trond Myklebust
2002-09-01 18:42               ` Luca Barbieri
2002-09-01 19:25                 ` Trond Myklebust
2002-09-01 21:36                   ` Luca Barbieri
2002-09-01 15:15         ` Daniel Phillips
2002-09-01 15:35           ` Luca Barbieri
     [not found] <15728.61345.184030.293634@charged.uio.no>
2002-08-31 18:57 ` Luca Barbieri
2002-08-31 19:51 ` Luca Barbieri
2002-08-31 16:32 Trond Myklebust

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1030835635.1422.39.camel@ldb \
    --to=ldb@ldb.ods.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    --cc=trond.myklebust@fys.uio.no \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).