[Devel] [PATCH RH9 5/5] netlink: add an option to set sk->err from userspace

Cyrill Gorcunov gorcunov at gmail.com
Tue Oct 5 20:54:50 MSK 2021


From: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>

Sometimes during dump criu can encounter sockets with overflown kernel
buffer, which results in ENOBUFS error during next read.
We need a reliable way to restore sk->sk_err.

https://jira.sw.ru/browse/PSBM-120976

Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
Signed-off-by: Cyrill Gorcunov <gorcunov at virtuozzo.com>
---
 include/uapi/linux/netlink.h |  1 +
 net/netlink/af_netlink.c     | 10 ++++++++++
 2 files changed, 11 insertions(+)

diff --git a/include/uapi/linux/netlink.h b/include/uapi/linux/netlink.h
index cdab1c041913..06e96450ecca 100644
--- a/include/uapi/linux/netlink.h
+++ b/include/uapi/linux/netlink.h
@@ -160,6 +160,7 @@ enum nlmsgerr_attrs {
 #define NETLINK_EXT_ACK			11
 #define NETLINK_GET_STRICT_CHK		12
 #define NETLINK_REPAIR			127
+#define NETLINK_SETERR			128
 
 struct nl_pktinfo {
 	__u32	group;
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 7eadbb5f01c4..4dc2b319ed5c 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -1686,6 +1686,16 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname,
 			nlk->flags &= ~NETLINK_F_REPAIR;
 		err = 0;
 		break;
+	case NETLINK_SETERR:
+		err = -ENOPROTOOPT;
+		if (nlk->flags & NETLINK_F_REPAIR) {
+			if (!val || val > MAX_ERRNO)
+				return -EINVAL;
+			sk->sk_err = val;
+			sk->sk_error_report(sk);
+			err = 0;
+		}
+		break;
 	case NETLINK_PKTINFO:
 		if (val)
 			nlk->flags |= NETLINK_F_RECV_PKTINFO;
-- 
2.31.1



More information about the Devel mailing list