UPSTREAM: fix handling of nd->depth on LOOKUP_CACHED failures in try_to_unlazy*
[ Upstream commit eacd9aa8cedeb412842c7b339adbaa0477fdd5ad ]
After switching to non-RCU mode, we want nd->depth to match the number
of entries in nd->stack[] that need eventual path_put().
legitimize_links() takes care of that on failures; unfortunately,
failure exits added for LOOKUP_CACHED do not.
We could add the logics for that into those failure exits, both in
try_to_unlazy() and in try_to_unlazy_next(), but since both checks
are immediately followed by legitimize_links() and there's no calls
of legitimize_links() other than those two... It's easier to
move the check (and required handling of nd->depth on failure) into
legitimize_links() itself.
[caught by Jens: ... and since we are zeroing ->depth here, we need
to do drop_links() first]
Fixes: 6c6ec2b0a3e0 "fs: add support for LOOKUP_CACHED"
Tested-by: Jens Axboe <axboe@kernel.dk>
Change-Id: I6cf685bfce81acb4d68c3991b2a936968a39c739
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 146fe79fff
)
Bug: 268174392
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
7928a1689b
commit
eaf736aa71
@@ -633,6 +633,11 @@ static inline bool legitimize_path(struct nameidata *nd,
|
|||||||
static bool legitimize_links(struct nameidata *nd)
|
static bool legitimize_links(struct nameidata *nd)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
if (unlikely(nd->flags & LOOKUP_CACHED)) {
|
||||||
|
drop_links(nd);
|
||||||
|
nd->depth = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
for (i = 0; i < nd->depth; i++) {
|
for (i = 0; i < nd->depth; i++) {
|
||||||
struct saved *last = nd->stack + i;
|
struct saved *last = nd->stack + i;
|
||||||
if (unlikely(!legitimize_path(nd, &last->link, last->seq))) {
|
if (unlikely(!legitimize_path(nd, &last->link, last->seq))) {
|
||||||
@@ -689,8 +694,6 @@ static bool try_to_unlazy(struct nameidata *nd)
|
|||||||
BUG_ON(!(nd->flags & LOOKUP_RCU));
|
BUG_ON(!(nd->flags & LOOKUP_RCU));
|
||||||
|
|
||||||
nd->flags &= ~LOOKUP_RCU;
|
nd->flags &= ~LOOKUP_RCU;
|
||||||
if (nd->flags & LOOKUP_CACHED)
|
|
||||||
goto out1;
|
|
||||||
if (unlikely(!legitimize_links(nd)))
|
if (unlikely(!legitimize_links(nd)))
|
||||||
goto out1;
|
goto out1;
|
||||||
if (unlikely(!legitimize_path(nd, &nd->path, nd->seq)))
|
if (unlikely(!legitimize_path(nd, &nd->path, nd->seq)))
|
||||||
@@ -727,8 +730,6 @@ static bool try_to_unlazy_next(struct nameidata *nd, struct dentry *dentry, unsi
|
|||||||
BUG_ON(!(nd->flags & LOOKUP_RCU));
|
BUG_ON(!(nd->flags & LOOKUP_RCU));
|
||||||
|
|
||||||
nd->flags &= ~LOOKUP_RCU;
|
nd->flags &= ~LOOKUP_RCU;
|
||||||
if (nd->flags & LOOKUP_CACHED)
|
|
||||||
goto out2;
|
|
||||||
if (unlikely(!legitimize_links(nd)))
|
if (unlikely(!legitimize_links(nd)))
|
||||||
goto out2;
|
goto out2;
|
||||||
if (unlikely(!legitimize_mnt(nd->path.mnt, nd->m_seq)))
|
if (unlikely(!legitimize_mnt(nd->path.mnt, nd->m_seq)))
|
||||||
|
Reference in New Issue
Block a user