mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 18:41:58 +09:00
Revert "sock_diag: allow concurrent operation in sock_diag_rcv_msg()"
This reverts commit adf8650938 which is
commit 86e8921df05c6e9423ab74ab8d41022775d8b83a upstream.
It breaks the Android kernel abi and can be brought back in the future
in an abi-safe way if it is really needed.
Bug: 161946584
Change-Id: If4e7565a3a8661f82d177129ad864452f84cdb3f
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This commit is contained in:
@@ -23,13 +23,8 @@ struct sock_diag_handler {
|
|||||||
int sock_diag_register(const struct sock_diag_handler *h);
|
int sock_diag_register(const struct sock_diag_handler *h);
|
||||||
void sock_diag_unregister(const struct sock_diag_handler *h);
|
void sock_diag_unregister(const struct sock_diag_handler *h);
|
||||||
|
|
||||||
struct sock_diag_inet_compat {
|
void sock_diag_register_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh));
|
||||||
struct module *owner;
|
void sock_diag_unregister_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh));
|
||||||
int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh);
|
|
||||||
};
|
|
||||||
|
|
||||||
void sock_diag_register_inet_compat(const struct sock_diag_inet_compat *ptr);
|
|
||||||
void sock_diag_unregister_inet_compat(const struct sock_diag_inet_compat *ptr);
|
|
||||||
|
|
||||||
u64 __sock_gen_cookie(struct sock *sk);
|
u64 __sock_gen_cookie(struct sock *sk);
|
||||||
|
|
||||||
|
|||||||
@@ -17,9 +17,8 @@
|
|||||||
#include <linux/sock_diag.h>
|
#include <linux/sock_diag.h>
|
||||||
|
|
||||||
static const struct sock_diag_handler __rcu *sock_diag_handlers[AF_MAX];
|
static const struct sock_diag_handler __rcu *sock_diag_handlers[AF_MAX];
|
||||||
|
static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
|
||||||
static struct sock_diag_inet_compat __rcu *inet_rcv_compat;
|
static DEFINE_MUTEX(sock_diag_table_mutex);
|
||||||
|
|
||||||
static struct workqueue_struct *broadcast_wq;
|
static struct workqueue_struct *broadcast_wq;
|
||||||
|
|
||||||
DEFINE_COOKIE(sock_cookie);
|
DEFINE_COOKIE(sock_cookie);
|
||||||
@@ -182,20 +181,19 @@ void sock_diag_broadcast_destroy(struct sock *sk)
|
|||||||
queue_work(broadcast_wq, &bsk->work);
|
queue_work(broadcast_wq, &bsk->work);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sock_diag_register_inet_compat(const struct sock_diag_inet_compat *ptr)
|
void sock_diag_register_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh))
|
||||||
{
|
{
|
||||||
xchg((__force const struct sock_diag_inet_compat **)&inet_rcv_compat,
|
mutex_lock(&sock_diag_table_mutex);
|
||||||
ptr);
|
inet_rcv_compat = fn;
|
||||||
|
mutex_unlock(&sock_diag_table_mutex);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(sock_diag_register_inet_compat);
|
EXPORT_SYMBOL_GPL(sock_diag_register_inet_compat);
|
||||||
|
|
||||||
void sock_diag_unregister_inet_compat(const struct sock_diag_inet_compat *ptr)
|
void sock_diag_unregister_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh))
|
||||||
{
|
{
|
||||||
const struct sock_diag_inet_compat *old;
|
mutex_lock(&sock_diag_table_mutex);
|
||||||
|
inet_rcv_compat = NULL;
|
||||||
old = xchg((__force const struct sock_diag_inet_compat **)&inet_rcv_compat,
|
mutex_unlock(&sock_diag_table_mutex);
|
||||||
NULL);
|
|
||||||
WARN_ON_ONCE(old != ptr);
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(sock_diag_unregister_inet_compat);
|
EXPORT_SYMBOL_GPL(sock_diag_unregister_inet_compat);
|
||||||
|
|
||||||
@@ -258,27 +256,20 @@ static int __sock_diag_cmd(struct sk_buff *skb, struct nlmsghdr *nlh)
|
|||||||
static int sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
|
static int sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
|
||||||
struct netlink_ext_ack *extack)
|
struct netlink_ext_ack *extack)
|
||||||
{
|
{
|
||||||
const struct sock_diag_inet_compat *ptr;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
switch (nlh->nlmsg_type) {
|
switch (nlh->nlmsg_type) {
|
||||||
case TCPDIAG_GETSOCK:
|
case TCPDIAG_GETSOCK:
|
||||||
case DCCPDIAG_GETSOCK:
|
case DCCPDIAG_GETSOCK:
|
||||||
|
if (inet_rcv_compat == NULL)
|
||||||
if (!rcu_access_pointer(inet_rcv_compat))
|
|
||||||
sock_load_diag_module(AF_INET, 0);
|
sock_load_diag_module(AF_INET, 0);
|
||||||
|
|
||||||
rcu_read_lock();
|
mutex_lock(&sock_diag_table_mutex);
|
||||||
ptr = rcu_dereference(inet_rcv_compat);
|
if (inet_rcv_compat != NULL)
|
||||||
if (ptr && !try_module_get(ptr->owner))
|
ret = inet_rcv_compat(skb, nlh);
|
||||||
ptr = NULL;
|
else
|
||||||
rcu_read_unlock();
|
ret = -EOPNOTSUPP;
|
||||||
|
mutex_unlock(&sock_diag_table_mutex);
|
||||||
ret = -EOPNOTSUPP;
|
|
||||||
if (ptr) {
|
|
||||||
ret = ptr->fn(skb, nlh);
|
|
||||||
module_put(ptr->owner);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
case SOCK_DIAG_BY_FAMILY:
|
case SOCK_DIAG_BY_FAMILY:
|
||||||
|
|||||||
@@ -1445,11 +1445,6 @@ void inet_diag_unregister(const struct inet_diag_handler *h)
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(inet_diag_unregister);
|
EXPORT_SYMBOL_GPL(inet_diag_unregister);
|
||||||
|
|
||||||
static const struct sock_diag_inet_compat inet_diag_compat = {
|
|
||||||
.owner = THIS_MODULE,
|
|
||||||
.fn = inet_diag_rcv_msg_compat,
|
|
||||||
};
|
|
||||||
|
|
||||||
static int __init inet_diag_init(void)
|
static int __init inet_diag_init(void)
|
||||||
{
|
{
|
||||||
const int inet_diag_table_size = (IPPROTO_MAX *
|
const int inet_diag_table_size = (IPPROTO_MAX *
|
||||||
@@ -1468,7 +1463,7 @@ static int __init inet_diag_init(void)
|
|||||||
if (err)
|
if (err)
|
||||||
goto out_free_inet;
|
goto out_free_inet;
|
||||||
|
|
||||||
sock_diag_register_inet_compat(&inet_diag_compat);
|
sock_diag_register_inet_compat(inet_diag_rcv_msg_compat);
|
||||||
out:
|
out:
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
@@ -1483,7 +1478,7 @@ static void __exit inet_diag_exit(void)
|
|||||||
{
|
{
|
||||||
sock_diag_unregister(&inet6_diag_handler);
|
sock_diag_unregister(&inet6_diag_handler);
|
||||||
sock_diag_unregister(&inet_diag_handler);
|
sock_diag_unregister(&inet_diag_handler);
|
||||||
sock_diag_unregister_inet_compat(&inet_diag_compat);
|
sock_diag_unregister_inet_compat(inet_diag_rcv_msg_compat);
|
||||||
kfree(inet_diag_table);
|
kfree(inet_diag_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user