lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1227802623.4454.1759.camel@twins>
Date:	Thu, 27 Nov 2008 17:17:03 +0100
From:	Peter Zijlstra <a.p.zijlstra@...llo.nl>
To:	Eric Paris <eparis@...hat.com>
Cc:	linux-kernel@...r.kernel.org, malware-list@...ts.printk.net,
	viro@...iv.linux.org.uk, akpm@...ux-foundation.org,
	alan@...rguk.ukuu.org.uk, arjan@...radead.org, hch@...radead.org
Subject: Re: [PATCH -v3 5/8] fsnotify: unified filesystem notification
 backend

On Tue, 2008-11-25 at 12:21 -0500, Eric Paris wrote:
> +struct fsnotify_group *fsnotify_find_group(unsigned int group_num, unsigned long mask, struct fsnotify_ops *ops)
> +{
> +       struct fsnotify_group *group_iter;
> +       struct fsnotify_group *group = NULL;
> +
> +       mutex_lock(&fsnotify_grp_mutex);
> +       list_for_each_entry_rcu(group_iter, &fsnotify_groups, group_list) {
> +               if (group_iter->group_num == group_num) {
> +                       if ((group_iter->mask == mask) &&
> +                           (group_iter->ops == ops)) {
> +                               fsnotify_get_group(group_iter);
> +                               group = group_iter;
> +                       } else
> +                               group = ERR_PTR(-EEXIST);
> +                       goto out;
> +               }
> +       }
> +
> +       group = kmalloc(sizeof(struct fsnotify_group), GFP_KERNEL);
> +       if (!group) {
> +               group = ERR_PTR(-ENOMEM);
> +               goto out;
> +       }
> +
> +       atomic_set(&group->refcnt, 1);
> +
> +       group->group_num = group_num;
> +       group->mask = mask;
> +
> +       mutex_init(&group->notification_mutex);
> +       INIT_LIST_HEAD(&group->notification_list);
> +       init_waitqueue_head(&group->notification_waitq);
> +
> +       group->ops = ops;
> +
> +       /* add it */
> +       list_add_rcu(&group->group_list, &fsnotify_groups);
> +
> +out:
> +       mutex_unlock(&fsnotify_grp_mutex);
> +       fsnotify_recalc_global_mask();
> +       return group;
> +}

Can't you do a lockless lookup and handle the insertion race?

Also, since it creates the object if its not found, _find_ might not be
the best name, how about obtain?

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ