Re: find: WARNING: Hard link count is wrong for /proc/1

From: Vegard Nossum
Date: Tue Jun 03 2008 - 00:07:05 EST


On Tue, Jun 3, 2008 at 5:46 AM, Eric W. Biederman <ebiederm@xxxxxxxxxxxx> wrote:
> Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> writes:
>>> #ifdef CONFIG_SECURITY
>>> inode->i_nlink += 1;
>>> #endif
>>> +#ifdef CONFIG_NET
>>> + inode->i_nlink += 1;
>>> +#endif
>>>
>>> dentry->d_op = &pid_dentry_operations;
>>
>> A bit more explanation would be nice.
>>
>> I assume that here we're accounting for a reference which net applies
>> to this dentry. But it would be clearer and more robust to do that at
>> the site where that reference is really taken, not over in
>> proc_pid_instantiate(). Possible?
>
> Yes. Potentially we can read through the tid_base_stuff and
> count the total number of directories at runtime whenever we
> open a /proc/<pid> directory. It is a smallish table and walking the
> entire table is likely to be lost in the noise, and that would
> certainly improve the maintainability of the code.
>
> Currently what we do is:
> inode->i_nlink = 5;
> #ifdef CONFIG_SECURITY
> inode->i_nlink += 1;
> #endif
>
> To get the hard link count of /proc/<pid> correct.
> With /proc/<pid>/net we have added one more optional possibly absent
> directory.
>
> So the above patch is trivially correct in the current form of the
> code but does not improve maintenance.
>
> I am tired and all I have the energy to do today is to review the
> patch and say: "Yes. The patch works for the correct reasons, let's
> fix this bug."

I can try for the counting fix if you give me a bit of time. I have an
exam today and tomorrow, so I'll likely be able to submit a fix after
that :-)

Maybe you can apply the fix for now and I can follow up with the nicer
counting patch afterwards? (Or if anybody else wants to write it
that's also fine :-))


Vegard

--
"The animistic metaphor of the bug that maliciously sneaked in while
the programmer was not looking is intellectually dishonest as it
disguises that the error is the programmer's own creation."
-- E. W. Dijkstra, EWD1036
--
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/