Re: [PATCH 26/30] cr: mount namespace

From: Dave Hansen
Date: Tue Apr 14 2009 - 14:53:46 EST


On Fri, 2009-04-10 at 06:40 +0400, Alexey Dobriyan wrote:
> +int cr_collect_all_mnt_ns(struct cr_context *ctx)
> +{
> + struct cr_object *obj;
> + int rv;
> +
> + for_each_cr_object(ctx, obj, CR_CTX_NSPROXY) {
> + struct nsproxy *nsproxy = obj->o_obj;
> +
> + rv = cr_collect_mnt_ns(ctx, nsproxy->mnt_ns);
> + if (rv < 0)
> + return rv;
> + }
> + for_each_cr_object(ctx, obj, CR_CTX_MNT_NS) {
> + struct mnt_namespace *mnt_ns = obj->o_obj;
> + unsigned int cnt = atomic_read(&mnt_ns->count);
> +
> + if (obj->o_count != cnt) {
> + printk("%s: mnt_ns %p has external references %lu:%u\n", __func__, mnt_ns, obj->o_count, cnt);
> + return -EINVAL;
> + }
> + }
> + return 0;
> +}

I worry about depending on refcounts like this, especially when
userspace has an interface that can elevate them. If someone is holding
open /proc/$pid/mounts, this will get elevated and trip the check. This
check is also naturally racy. You check once if there are references,
but there is no locking to keep new references from coming in.

That said, I do like how this for_each_cr_object() stuff looks. It's
pretty clean.

-- Dave

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/