Re: [Question] Should `CAP_NET_ADMIN` be needed when opening `/dev/ppp`?

From: 王邈
Date: Tue May 03 2016 - 09:08:46 EST



> 在 2016年5月3日,下午7:23,Hannes Frederic Sowa <hannes@xxxxxxxxxxxxxxxxxxx> 写道:
>
> On Tue, May 3, 2016, at 12:35, Richard Weinberger wrote:
>> On Tue, May 3, 2016 at 12:12 PM, Guillaume Nault <g.nault@xxxxxxxxxxxx>
>> wrote:
>>> On Sun, May 01, 2016 at 09:38:57PM +0800, Wang Shanker wrote:
>>>> static int ppp_open(struct inode *inode, struct file *file)
>>>> {
>>>> /*
>>>> * This could (should?) be enforced by the permissions on /dev/ppp.
>>>> */
>>>> if (!capable(CAP_NET_ADMIN))
>>>> return -EPERM;
>>>> return 0;
>>>> }
>>>> ```
>>>>
>>>> I wonder why CAP_NET_ADMIN is needed here, rather than leaving it to the
>>>> permission of the device node. If there is no need, I suggest that the
>>>> CAP_NET_ADMIN check be removed.
>>>>
>>> If this test was removed here, then it'd have to be added again in the
>>> PPPIOCNEWUNIT ioctl, at the very least, because creating a netdevice
>>> should require CAP_NET_ADMIN. Therefore that wouldn't help for your
>>> case.
>>> I don't know why the test was placed in ppp_open() in the first place,
>>> but changing it now would have side effects on user space. So I'd
>>> rather leave the code as is.
>>
>> I think the question is whether we really require having CAP_NET_ADMIN
>> in the initial namespace and not just in the current one.
>> Is ppp not network namespace aware?
>
> I agree, ns_capable(net->user_ns, CAP_NET_ADMIN), would probably make
> more sense.
I agree with that.
>
> Bye,
> Hannes