Re: [PATCH] sysfs: only allow one scheduled removal callback perkobj

From: Cornelia Huck
Date: Mon Mar 16 2009 - 06:16:08 EST


On Fri, 13 Mar 2009 12:07:36 -0600,
Alex Chiang <achiang@xxxxxx> wrote:

> The only way for a sysfs attribute to remove itself (without
> deadlock) is to use the sysfs_schedule_callback() interface.
>
> Vegard Nossum discovered that a poorly written sysfs ->store
> callback can repeatedly schedule remove callbacks on the same
> device over and over, e.g.
>
> $ while true ; do echo 1 > /sys/devices/.../remove ; done
>
> If the 'remove' attribute uses the sysfs_schedule_callback API
> and also does not protect itself from concurrent accesses, its
> callback handler will be called multiple times, and will
> eventually attempt to perform operations on a freed kobject,
> leading to many problems.
>
> Instead of requiring all callers of sysfs_schedule_callback to
> implement their own synchronization, provide the protection in
> the infrastructure.
>
> Now, sysfs_schedule_callback will only allow one scheduled
> callback per kobject. On subsequent calls with the same kobject,
> return -EAGAIN.
>
> This is a short term fix. The long term fix is to allow sysfs
> attributes to remove themselves directly, without any of this
> callback hokey pokey.
>
> [cornelia.huck@xxxxxxxxxx: s390 ccwgroup bits]
> Cc: cornelia.huck@xxxxxxxxxx
> Reported-by: vegard.nossum@xxxxxxxxx
> Signed-off-by: Alex Chiang <achiang@xxxxxx>
> ---
> drivers/s390/cio/ccwgroup.c | 5 +++--
> fs/sysfs/file.c | 26 +++++++++++++++++++++++---
> 2 files changed, 26 insertions(+), 5 deletions(-)

Acked-by: Cornelia Huck <cornelia.huck@xxxxxxxxxx>
--
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/