提交 baff4b7b 编写于 作者: T Trond Myklebust 提交者: Zheng Zengkai

SUNRPC: Close a race with transport setup and module put

hulk inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I4IL3P
CVE: NA

--------------------------------

After we've looked up the transport module, we need to ensure it can't
go away until we've finished running the transport setup code.
Signed-off-by: NTrond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: NLu Wei <luwei32@huawei.com>
Reviewed-by: NWei Yongjun <weiyongjun1@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 a41f60f0
...@@ -158,6 +158,32 @@ xprt_class_release(const struct xprt_class *t) ...@@ -158,6 +158,32 @@ xprt_class_release(const struct xprt_class *t)
module_put(t->owner); module_put(t->owner);
} }
static const struct xprt_class *
xprt_class_find_by_ident_locked(int ident)
{
const struct xprt_class *t;
list_for_each_entry(t, &xprt_list, list) {
if (t->ident != ident)
continue;
if (!try_module_get(t->owner))
continue;
return t;
}
return NULL;
}
static const struct xprt_class *
xprt_class_find_by_ident(int ident)
{
const struct xprt_class *t;
spin_lock(&xprt_list_lock);
t = xprt_class_find_by_ident_locked(ident);
spin_unlock(&xprt_list_lock);
return t;
}
static const struct xprt_class * static const struct xprt_class *
xprt_class_find_by_netid_locked(const char *netid) xprt_class_find_by_netid_locked(const char *netid)
{ {
...@@ -1959,21 +1985,17 @@ static void xprt_init(struct rpc_xprt *xprt, struct net *net) ...@@ -1959,21 +1985,17 @@ static void xprt_init(struct rpc_xprt *xprt, struct net *net)
struct rpc_xprt *xprt_create_transport(struct xprt_create *args) struct rpc_xprt *xprt_create_transport(struct xprt_create *args)
{ {
struct rpc_xprt *xprt; struct rpc_xprt *xprt;
struct xprt_class *t; const struct xprt_class *t;
spin_lock(&xprt_list_lock); t = xprt_class_find_by_ident(args->ident);
list_for_each_entry(t, &xprt_list, list) { if (!t) {
if (t->ident == args->ident) { dprintk("RPC: transport (%d) not supported\n", args->ident);
spin_unlock(&xprt_list_lock); return ERR_PTR(-EIO);
goto found;
}
} }
spin_unlock(&xprt_list_lock);
dprintk("RPC: transport (%d) not supported\n", args->ident);
return ERR_PTR(-EIO);
found:
xprt = t->setup(args); xprt = t->setup(args);
xprt_class_release(t);
if (IS_ERR(xprt)) if (IS_ERR(xprt))
goto out; goto out;
if (args->flags & XPRT_CREATE_NO_IDLE_TIMEOUT) if (args->flags & XPRT_CREATE_NO_IDLE_TIMEOUT)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册