Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1405006

Re: [PATCH v6 2/8] debugfs: prevent access to removed files' private data

From Nicolai Stange <nicstange@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH v6 2/8] debugfs: prevent access to removed files' private data
Date 2016-05-22 15:30 +0200
Message-ID <rBBCe-1hd-7@gated-at.bofh.it> (permalink)
References (3 earlier) <rAbgL-3KP-35@gated-at.bofh.it> <rAbqq-3On-29@gated-at.bofh.it> <rAccO-4lF-9@gated-at.bofh.it> <rAVWi-80D-13@gated-at.bofh.it> <rBjlU-6zE-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

Nicolai Stange <nicstange@gmail.com> writes:

> Sasha Levin <sasha.levin@oracle.com> writes:
>
>> On 05/18/2016 12:05 PM, Greg Kroah-Hartman wrote:
>>> On Wed, May 18, 2016 at 11:18:16AM -0400, Sasha Levin wrote:
>>>> On 05/18/2016 11:01 AM, Nicolai Stange wrote:
>>>>> Thanks a million for reporting!
>>>>>
>>>>> 1.) Do you have lockdep enabled?
>>>>
>>>> Yup, nothing there.
>>>>
>>>>> 2.) Does this happen before or after userspace init has been spawned,
>>>>>     i.e. does the lockup happen at debugfs file creation time or
>>>>>     possibly at usage time?
>>>>
>>>> So I looked closer, and it seems to happen after starting syzkaller, which
>>>> as far as I know tries to open many different debugfs files.
>>>>
>>>> Is there debug code I can add it that'll help us figure out what's up?
>>> 
>>> Trying to figure out _which_ debugfs file is causing this would be
>>> great, if at all possible.  strace?
>>
>> What seems to be failing is syzkaller's attempt to mmap the coverage
>> debugfs file. So this isn't actually a kernel deadlock but syzkaller
>> misbehaves when that scenario happens.
>>
>> Either way, it only fails to mmap with that commit that I've pointed
>> out.
>
> That info is really helpful here: the proxy file_operations introduced by
> this commit doesn't have a ->mmap() defined, i.e. it is NULL from the
> VFS layer's point of view.
>
> The simple reason is that at the time I submitted this series, my
> Coccinelle script didn't find any debugfs user with a ->mmap()
> defined. Thus either that script was broken or things have changed in
> the meanwhile.

Thankfully, it's the latter :)
See the attached cocci script I used back then.

It now reports:

  ./drivers/staging/android/sync_debug.c:330:1-20: unsupported file_operations given to debugfs
  ./kernel/kcov.c:267:6-25: unsupported file_operations given to debugfs

The kcov's ->mmap() has been introduced by

  5c9a8750a640 ("kernel: add kcov code coverage")

dated from March this year.

Since that kcov debugfs file is never removed, it needs no protecting
proxy and thus, a replacement of debugfs_create_file() by
debugfs_create_file_unsafe() will do the trick here.

I'll send patches addressing the above two issues.

>>
>> 	th->cover_fd = open("/sys/kernel/debug/kcov", O_RDWR);
>> 	if (th->cover_fd == -1)
>> 		fail("open of /sys/kernel/debug/kcov failed");
>> 	if (ioctl(th->cover_fd, KCOV_INIT_TRACE, kCoverSize))
>> 		fail("cover enable write failed");
>> 	th->cover_data = (uintptr_t*)mmap(NULL, kCoverSize * sizeof(th->cover_data[0]), PROT_READ | PROT_WRITE, MAP_SHARED, th->cover_fd, 0);
>> 	if ((void*)th->cover_data == MAP_FAILED)
>> 		fail("cover mmap failed");
>>
>> And it's the mmap() that fails with -ENODEV.

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [PATCH v6 2/8] debugfs: prevent access to removed files' private  data Sasha Levin <sasha.levin@oracle.com> - 2016-05-18 16:50 +0200
  Re: [PATCH v6 2/8] debugfs: prevent access to removed files' private data Nicolai Stange <nicstange@gmail.com> - 2016-05-18 17:10 +0200
    Re: [PATCH v6 2/8] debugfs: prevent access to removed files' private  data Sasha Levin <sasha.levin@oracle.com> - 2016-05-18 17:20 +0200
      Re: [PATCH v6 2/8] debugfs: prevent access to removed files' private  data Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-05-18 18:10 +0200
        Re: [PATCH v6 2/8] debugfs: prevent access to removed files' private  data Sasha Levin <sasha.levin@oracle.com> - 2016-05-20 19:00 +0200
          Re: [PATCH v6 2/8] debugfs: prevent access to removed files' private data Nicolai Stange <nicstange@gmail.com> - 2016-05-21 20:00 +0200
            Re: [PATCH v6 2/8] debugfs: prevent access to removed files' private data Nicolai Stange <nicstange@gmail.com> - 2016-05-22 15:30 +0200
      Re: [PATCH v6 2/8] debugfs: prevent access to removed files' private data Nicolai Stange <nicstange@gmail.com> - 2016-05-18 18:40 +0200
        Re: [PATCH v6 2/8] debugfs: prevent access to removed files' private  data Sasha Levin <sasha.levin@oracle.com> - 2016-05-20 19:00 +0200

csiph-web