dcache: fix locking bug in __dentry_path()
PATCH 1/1 dcache: fix locking bug in __dentry_path()
If given buffer size is zero, we forget to rcu_read_unlock() on error path.
--- fs/dcache.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/dcache.c +4 -1
@@ -3127,8 +3127,11 @@ restart: end = buf + buflen; len = buflen;prepend (&end, &len,"\0" ,1 ); -if (buflen <1 ) +if (buflen <1 ) { +if (!(seq &1 )) +rcu_read_unlock (); goto Elong; + }/* Get '/' right */ retval = end-1 ; *retval ='/' ;
Signature · 1 line
1.8.1.4
Al Viro
maintainerQuoted 2 lines · Denys Vlasenko
If given buffer size is zero, we forget to
rcu_read_unlock()on error path.
Er... Where could we ever get called with size zero? IOW, the real question is whether that check makes any sense. If nothing else, a much more obvious fix (again, assuming there is a call chain that could have triggered that in the first place), would be to take that
if (buflen < 1)
goto Elong;on the very top of __dentry_path(). Note that buflen never change, so this check could bloody well be handled once - and earlier. But again, the callers shouldn't be calling it that way...
Quoted 9 lines · Al Viro
Quoted 2 lines · Denys Vlasenko
If given buffer size is zero, we forget to
rcu_read_unlock()on error path.Er... Where could we ever get called with size zero? IOW, the real question is whether that check makes any sense. If nothing else, a much more obvious fix (again, assuming there is a call chain that could have triggered that in the first place), would be to take that
Quoted 5 lines
if (buflen < 1) goto Elong;on the very top of
__dentry_path(). Note that buflen never change, so this check could bloody well be handled once - and earlier.
Yes. In fact the check is buggier than I thought:
prepend(&end, &len, "\0", 1);
if (buflen < 1)
goto Elong;
/* Get '/' right */
retval = end-1;
*retval = '/'; <=== !!!It should be "buflen < 2". With buflen == 1, we touch buffer[-1].
Quoted 2 lines
But again, the callers shouldn't be calling it that way...
I'll add a check in d_path() and post another patch. I assume the assertion should be 'size >= 2', since path "" should never be produced anyway, the shortest path is "/"?
Signature · 1 line
vda