Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Linux: Kernel

[PATCH] unserialized task->files changing (v2)

 

 

Linux kernel RSS feed   Index | Next | Previous | View Threaded


dev at sw

Aug 8, 2006, 4:31 AM

Post #1 of 5 (192 views)
Permalink
[PATCH] unserialized task->files changing (v2)

Fixed race on put_files_struct on exec with proc.
Restoring files on current on error path may lead
to proc having a pointer to already kfree-d files_struct.

->files changing at exit.c and khtread.c are safe as
exit_files() makes all things under lock.

v2 patch changes:
- introduced reset_files_struct() as Christoph Hellwig suggested

Found during OpenVZ stress testing.

Signed-Off-By: Pavel Emelianov <xemul [at] openvz>
Signed-Off-By: Kirill Korotaev <dev [at] openvz>
Attachments: diff-ms-files-race-fix-200600808 (1.98 KB)


dada1 at cosmosbay

Aug 8, 2006, 5:51 AM

Post #2 of 5 (166 views)
Permalink
Re: [PATCH] unserialized task->files changing (v2) [In reply to]

On Tuesday 08 August 2006 13:31, Kirill Korotaev wrote:
> Fixed race on put_files_struct on exec with proc.
> Restoring files on current on error path may lead
> to proc having a pointer to already kfree-d files_struct.
>
> ->files changing at exit.c and khtread.c are safe as
> exit_files() makes all things under lock.
>
> v2 patch changes:
> - introduced reset_files_struct() as Christoph Hellwig suggested
>
> Found during OpenVZ stress testing.

Sorry but there is something I dont understand. You ignored my point.

+void reset_files_struct(struct task_struct *tsk, struct files_struct *files)
+{
+       struct files_struct *old;
+
+       old = tsk->files;
+       task_lock(tsk);
+       tsk->files = files;
+       task_unlock(tsk);
+       put_files_struct(old);
+}

Its seems very strange to protect tsk->files = files with a
task_lock()/task_unlock(). What is it supposed to guard against ???

If this patch corrects the 'bug', then a simpler fix would be to use a memory
barrier between "tsk->files = files" and "put_files_struct(old);"

No need to perform 2 atomics ops on the task lock.

old = tsk->files;
tsk->files = files;
smp_mb();
put_files_struct(old);

That would be enough to guard against proc code (because this code only needs
to read tsk->files of course)

The same remark can be said for __exit_files() from kernel/exit.c

If this task_lock()/task_unlock() patch is really needed, then a comment in
the source would be very fair.

Eric

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


xemul at sw

Aug 8, 2006, 6:18 AM

Post #3 of 5 (166 views)
Permalink
Re: [PATCH] unserialized task->files changing (v2) [In reply to]

Eric Dumazet wrote:
> On Tuesday 08 August 2006 13:31, Kirill Korotaev wrote:
>> Fixed race on put_files_struct on exec with proc.
>> Restoring files on current on error path may lead
>> to proc having a pointer to already kfree-d files_struct.
>>
>> ->files changing at exit.c and khtread.c are safe as
>> exit_files() makes all things under lock.
>>
>> v2 patch changes:
>> - introduced reset_files_struct() as Christoph Hellwig suggested
>>
>> Found during OpenVZ stress testing.
>
> Sorry but there is something I dont understand. You ignored my point.
>
> +void reset_files_struct(struct task_struct *tsk, struct files_struct
> *files)
> +{
> + struct files_struct *old;
> +
> + old = tsk->files;
> + task_lock(tsk);
> + tsk->files = files;
> + task_unlock(tsk);
> + put_files_struct(old);
> +}
>
> Its seems very strange to protect tsk->files = files with a
> task_lock()/task_unlock(). What is it supposed to guard against ???
>
> If this patch corrects the 'bug', then a simpler fix would be to use a
> memory
> barrier between "tsk->files = files" and "put_files_struct(old);"
>
> No need to perform 2 atomics ops on the task lock.
>
> old = tsk->files;
> tsk->files = files;
> smp_mb();
> put_files_struct(old);

No. The race being discussed is:

proc code: resetting code:
=============================================================================
task_lock(tsk);
files = tsk->files;
old = tsk->files;
tsk->files = files;
put_files_struct(old); /* dec to 0 */
`- kmem_cache_free(files);
get_files_struct(file); /* already free */
task_unlock(tsk);

So having smp_mb() before put_files_struct() does not fix the problem.

>
> That would be enough to guard against proc code (because this code
> only needs
> to read tsk->files of course)
>
> The same remark can be said for __exit_files() from kernel/exit.c
>
> If this task_lock()/task_unlock() patch is really needed, then a
> comment in
> the source would be very fair.
>
> Eric



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


dev at sw

Aug 8, 2006, 8:53 AM

Post #4 of 5 (161 views)
Permalink
Re: [PATCH] unserialized task->files changing (v2) [In reply to]

Eric,

> Sorry but there is something I dont understand. You ignored my point.
Sorry, I missed it thinking that you are talking about another thing...
Pavel described the race in more details and why barrier doesn't help.
Hope, it became more clear now.

> +void reset_files_struct(struct task_struct *tsk, struct files_struct *files)
> +{
> + struct files_struct *old;
> +
> + old = tsk->files;
> + task_lock(tsk);
> + tsk->files = files;
> + task_unlock(tsk);
> + put_files_struct(old);
> +}
>
> Its seems very strange to protect tsk->files = files with a
> task_lock()/task_unlock(). What is it supposed to guard against ???
>
> If this patch corrects the 'bug', then a simpler fix would be to use a memory
> barrier between "tsk->files = files" and "put_files_struct(old);"
>
> No need to perform 2 atomics ops on the task lock.
>
> old = tsk->files;
> tsk->files = files;
> smp_mb();
> put_files_struct(old);
>
> That would be enough to guard against proc code (because this code only needs
> to read tsk->files of course)
>
> The same remark can be said for __exit_files() from kernel/exit.c
>
> If this task_lock()/task_unlock() patch is really needed, then a comment in
> the source would be very fair.

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


dada1 at cosmosbay

Aug 8, 2006, 8:59 AM

Post #5 of 5 (167 views)
Permalink
Re: [PATCH] unserialized task->files changing (v2) [In reply to]

On Tuesday 08 August 2006 17:53, Kirill Korotaev wrote:
> Eric,
>
> > Sorry but there is something I dont understand. You ignored my point.
>
> Sorry, I missed it thinking that you are talking about another thing...
> Pavel described the race in more details and why barrier doesn't help.
> Hope, it became more clear now.

Yes it became very clear :)
Sorry for the confusion.

Thank you

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

Linux kernel RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.