* [PATCH V4 net-next 0/5] add support for RFC 8335 PROBE
@ 2021-03-14 16:48 Andreas Roeseler
2021-03-14 16:48 ` [PATCH V4 net-next 1/5] icmp: " Andreas Roeseler
` (4 more replies)
0 siblings, 5 replies; 18+ messages in thread
From: Andreas Roeseler @ 2021-03-14 16:48 UTC (permalink / raw)
To: davem; +Cc: yoshfuji, dsahern, kuba, netdev, Andreas Roeseler
The popular utility ping has several severe limitations, such as the
inability to query specific interfaces on a node and requiring
bidirectional connectivity between the probing and probed interfaces.
RFC 8335 attempts to solve these limitations by creating the new utility
PROBE which is a specialized ICMP message that makes use of the ICMP
Extension Structure outlined in RFC 4884.
This patchset adds definitions for the ICMP Extended Echo Request and
Reply (PROBE) types for both IPV4 and IPV6, adds a sysctl to enable
responses to PROBE messages, expands the list of supported ICMP messages
to accommodate PROBE types, and adds functionality to respond to PROBE
requests.
Changes:
v1 -> v2:
- Add AFI definitions
- Switch to functions such as dev_get_by_name and ip_dev_find to lookup
net devices
v2 -> v3:
Suggested by Willem de Bruijn <willemdebruijn.kernel@gmail.com>
- Add verification of incoming messages before looking up netdev
- Add prefix for PROBE specific defined variables
- Use proc_dointvec_minmax with zero and one for sysctl
- Create struct icmp_ext_echo_iio for parsing incoming packets
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
- Include net/addrconf.h library for ipv6_dev_find
v3 -> v4:
- Use in_addr instead of __be32 for storing IPV4 addresses
- Use IFNAMSIZ to statically allocate space for name in
icmp_ext_echo_iio
Suggested by Willem de Bruijn <willemdebruijn.kernel@gmail.com>
- Use skb_header_pointer to verify fields in incoming message
- Add check to ensure that extobj_hdr.length is valid
- Check to ensure object payload is padded with ASCII NULL characters
when probing by name, as specified by RFC 8335
- Statically allocate buff using IFNAMSIZ
- Add rcu blocking around ipv6_dev_find
- Use __in_dev_get_rcu to access IPV4 addresses of identified
net_device
- Remove check for ICMPV6 PROBE types
Andreas Roeseler (5):
icmp: add support for RFC 8335 PROBE
ICMPV6: add support for RFC 8335 PROBE
net: add sysctl for enabling RFC 8335 PROBE messages
net: add support for sending RFC 8335 PROBE messages
icmp: add response to RFC 8335 PROBE messages
include/net/netns/ipv4.h | 1 +
include/uapi/linux/icmp.h | 42 +++++++++++
include/uapi/linux/icmpv6.h | 3 +
net/ipv4/icmp.c | 145 ++++++++++++++++++++++++++++++++----
net/ipv4/ping.c | 4 +-
net/ipv4/sysctl_net_ipv4.c | 9 +++
6 files changed, 188 insertions(+), 16 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH V4 net-next 1/5] icmp: add support for RFC 8335 PROBE
2021-03-14 16:48 [PATCH V4 net-next 0/5] add support for RFC 8335 PROBE Andreas Roeseler
@ 2021-03-14 16:48 ` Andreas Roeseler
2021-03-14 16:48 ` [PATCH V4 net-next 2/5] ICMPV6: " Andreas Roeseler
` (3 subsequent siblings)
4 siblings, 0 replies; 18+ messages in thread
From: Andreas Roeseler @ 2021-03-14 16:48 UTC (permalink / raw)
To: davem; +Cc: yoshfuji, dsahern, kuba, netdev, Andreas Roeseler
Add definitions for PROBE ICMP types and codes.
Add AFI definitions for IP and IPV6 as specified by IANA
Add a struct to represent the additional header when probing by IP
address (ctype == 3) for use in parsing incoming PROBE messages
Add a struct to represent the entire Interface Identification Object
(IIO) section of an incoming PROBE packet
Signed-off-by: Andreas Roeseler <andreas.a.roeseler@gmail.com>
---
Changes:
v1 -> v2:
- Add AFI_IP and AFI_IP6 definitions
v2 -> v3:
Suggested by Willem de Bruijn <willemdebruijn.kernel@gmail.com>
- Add prefix for PROBE specific defined variables
- Create struct icmp_ext_echo_iio for parsing incoming packet
v3 -> v4:
- Use in_addr instead of __be32 for storing IPV4 addresses
- Use IFNAMSIZ to statically allocate space for name in
icmp_ext_echo_iio
---
include/uapi/linux/icmp.h | 42 +++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/include/uapi/linux/icmp.h b/include/uapi/linux/icmp.h
index fb169a50895e..c074964aa4f3 100644
--- a/include/uapi/linux/icmp.h
+++ b/include/uapi/linux/icmp.h
@@ -20,6 +20,9 @@
#include <linux/types.h>
#include <asm/byteorder.h>
+#include <linux/in.h>
+#include <linux/if.h>
+#include <linux/in6.h>
#define ICMP_ECHOREPLY 0 /* Echo Reply */
#define ICMP_DEST_UNREACH 3 /* Destination Unreachable */
@@ -66,6 +69,23 @@
#define ICMP_EXC_TTL 0 /* TTL count exceeded */
#define ICMP_EXC_FRAGTIME 1 /* Fragment Reass time exceeded */
+/* Codes for EXT_ECHO (PROBE) */
+#define ICMP_EXT_ECHO 42
+#define ICMP_EXT_ECHOREPLY 43
+#define ICMP_EXT_MAL_QUERY 1 /* Malformed Query */
+#define ICMP_EXT_NO_IF 2 /* No such Interface */
+#define ICMP_EXT_NO_TABLE_ENT 3 /* No such Table Entry */
+#define ICMP_EXT_MULT_IFS 4 /* Multiple Interfaces Satisfy Query */
+
+/* Constants for EXT_ECHO (PROBE) */
+#define EXT_ECHOREPLY_ACTIVE (1 << 2)/* active bit in reply message */
+#define EXT_ECHOREPLY_IPV4 (1 << 1)/* ipv4 bit in reply message */
+#define EXT_ECHOREPLY_IPV6 1 /* ipv6 bit in reply message */
+#define EXT_ECHO_CTYPE_NAME 1
+#define EXT_ECHO_CTYPE_INDEX 2
+#define EXT_ECHO_CTYPE_ADDR 3
+#define ICMP_AFI_IP 1 /* Address Family Identifier for ipv4 */
+#define ICMP_AFI_IP6 2 /* Address Family Identifier for ipv6 */
struct icmphdr {
__u8 type;
@@ -118,4 +138,26 @@ struct icmp_extobj_hdr {
__u8 class_type;
};
+/* RFC 8335: 2.1 Header for c-type 3 payload */
+struct icmp_ext_echo_ctype3_hdr {
+ __u16 afi;
+ __u8 addrlen;
+ __u8 reserved;
+};
+
+/* RFC 8335: 2.1 Interface Identification Object */
+struct icmp_ext_echo_iio {
+ struct icmp_extobj_hdr extobj_hdr;
+ union {
+ char name[IFNAMSIZ];
+ __u32 ifindex;
+ struct {
+ struct icmp_ext_echo_ctype3_hdr ctype3_hdr;
+ union {
+ struct in_addr ipv4_addr;
+ struct in6_addr ipv6_addr;
+ } ip_addr;
+ } addr;
+ } ident;
+};
#endif /* _UAPI_LINUX_ICMP_H */
--
2.17.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH V4 net-next 2/5] ICMPV6: add support for RFC 8335 PROBE
2021-03-14 16:48 [PATCH V4 net-next 0/5] add support for RFC 8335 PROBE Andreas Roeseler
2021-03-14 16:48 ` [PATCH V4 net-next 1/5] icmp: " Andreas Roeseler
@ 2021-03-14 16:48 ` Andreas Roeseler
2021-03-14 16:48 ` [PATCH V4 net-next 3/5] net: add sysctl for enabling RFC 8335 PROBE messages Andreas Roeseler
` (2 subsequent siblings)
4 siblings, 0 replies; 18+ messages in thread
From: Andreas Roeseler @ 2021-03-14 16:48 UTC (permalink / raw)
To: davem; +Cc: yoshfuji, dsahern, kuba, netdev, Andreas Roeseler
Add definitions for the ICMPV6 type of Extended Echo Request and
Extended Echo Reply, as defined by sections 2 and 3 of RFC 8335.
Signed-off-by: Andreas Roeseler <andreas.a.roeseler@gmail.com>
---
include/uapi/linux/icmpv6.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/include/uapi/linux/icmpv6.h b/include/uapi/linux/icmpv6.h
index 0564fd7ccde4..ecaece3af38d 100644
--- a/include/uapi/linux/icmpv6.h
+++ b/include/uapi/linux/icmpv6.h
@@ -140,6 +140,9 @@ struct icmp6hdr {
#define ICMPV6_UNK_OPTION 2
#define ICMPV6_HDR_INCOMP 3
+/* Codes for EXT_ECHO (PROBE) */
+#define ICMPV6_EXT_ECHO_REQUEST 160
+#define ICMPV6_EXT_ECHO_REPLY 161
/*
* constants for (set|get)sockopt
*/
--
2.17.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH V4 net-next 3/5] net: add sysctl for enabling RFC 8335 PROBE messages
2021-03-14 16:48 [PATCH V4 net-next 0/5] add support for RFC 8335 PROBE Andreas Roeseler
2021-03-14 16:48 ` [PATCH V4 net-next 1/5] icmp: " Andreas Roeseler
2021-03-14 16:48 ` [PATCH V4 net-next 2/5] ICMPV6: " Andreas Roeseler
@ 2021-03-14 16:48 ` Andreas Roeseler
2021-03-14 16:48 ` [PATCH V4 net-next 4/5] net: add support for sending " Andreas Roeseler
2021-03-14 16:48 ` [PATCH V4 net-next 5/5] icmp: add response to " Andreas Roeseler
4 siblings, 0 replies; 18+ messages in thread
From: Andreas Roeseler @ 2021-03-14 16:48 UTC (permalink / raw)
To: davem; +Cc: yoshfuji, dsahern, kuba, netdev, Andreas Roeseler
Section 8 of RFC 8335 specifies potential security concerns of
responding to PROBE requests, and states that nodes that support PROBE
functionality MUST be able to enable/disable responses and that
responses MUST be disabled by default
Signed-off-by: Andreas Roeseler <andreas.a.roeseler@gmail.com>
---
Changes:
v1 -> v2:
- Combine patches related to sysctl
v2 -> v3:
Suggested by Willem de Bruijn <willemdebruijn.kernel@gmail.com>
- Use proc_dointvec_minmax with zero and one
---
include/net/netns/ipv4.h | 1 +
net/ipv4/sysctl_net_ipv4.c | 9 +++++++++
2 files changed, 10 insertions(+)
diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
index 70a2a085dd1a..362388ab40c8 100644
--- a/include/net/netns/ipv4.h
+++ b/include/net/netns/ipv4.h
@@ -85,6 +85,7 @@ struct netns_ipv4 {
#endif
int sysctl_icmp_echo_ignore_all;
+ int sysctl_icmp_echo_enable_probe;
int sysctl_icmp_echo_ignore_broadcasts;
int sysctl_icmp_ignore_bogus_error_responses;
int sysctl_icmp_ratelimit;
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index f55095d3ed16..fec3f142d8c9 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -599,6 +599,15 @@ static struct ctl_table ipv4_net_table[] = {
.mode = 0644,
.proc_handler = proc_dointvec
},
+ {
+ .procname = "icmp_echo_enable_probe",
+ .data = &init_net.ipv4.sysctl_icmp_echo_enable_probe,
+ .maxlen = sizeof(int),
+ .mode = 0644,
+ .proc_handler = proc_dointvec_minmax,
+ .extra1 = SYSCTL_ZERO,
+ .extra2 = SYSCTL_ONE
+ },
{
.procname = "icmp_echo_ignore_broadcasts",
.data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
--
2.17.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH V4 net-next 4/5] net: add support for sending RFC 8335 PROBE messages
2021-03-14 16:48 [PATCH V4 net-next 0/5] add support for RFC 8335 PROBE Andreas Roeseler
` (2 preceding siblings ...)
2021-03-14 16:48 ` [PATCH V4 net-next 3/5] net: add sysctl for enabling RFC 8335 PROBE messages Andreas Roeseler
@ 2021-03-14 16:48 ` Andreas Roeseler
2021-03-14 16:48 ` [PATCH V4 net-next 5/5] icmp: add response to " Andreas Roeseler
4 siblings, 0 replies; 18+ messages in thread
From: Andreas Roeseler @ 2021-03-14 16:48 UTC (permalink / raw)
To: davem; +Cc: yoshfuji, dsahern, kuba, netdev, Andreas Roeseler
Modify the ping_supported function to support PROBE message types. This
allows tools such as the ping command in the iputils package to be
modified to send PROBE requests through the existing framework for
sending ping requests.
Signed-off-by: Andreas Roeseler <andreas.a.roeseler@gmail.com>
---
net/ipv4/ping.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
index 8b943f85fff9..1c9f71a37258 100644
--- a/net/ipv4/ping.c
+++ b/net/ipv4/ping.c
@@ -453,7 +453,9 @@ EXPORT_SYMBOL_GPL(ping_bind);
static inline int ping_supported(int family, int type, int code)
{
return (family == AF_INET && type == ICMP_ECHO && code == 0) ||
- (family == AF_INET6 && type == ICMPV6_ECHO_REQUEST && code == 0);
+ (family == AF_INET && type == ICMP_EXT_ECHO && code == 0) ||
+ (family == AF_INET6 && type == ICMPV6_ECHO_REQUEST && code == 0) ||
+ (family == AF_INET6 && type == ICMPV6_EXT_ECHO_REQUEST && code == 0);
}
/*
--
2.17.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH V4 net-next 5/5] icmp: add response to RFC 8335 PROBE messages
2021-03-14 16:48 [PATCH V4 net-next 0/5] add support for RFC 8335 PROBE Andreas Roeseler
` (3 preceding siblings ...)
2021-03-14 16:48 ` [PATCH V4 net-next 4/5] net: add support for sending " Andreas Roeseler
@ 2021-03-14 16:48 ` Andreas Roeseler
2021-03-14 17:59 ` kernel test robot
` (4 more replies)
4 siblings, 5 replies; 18+ messages in thread
From: Andreas Roeseler @ 2021-03-14 16:48 UTC (permalink / raw)
To: davem; +Cc: yoshfuji, dsahern, kuba, netdev, Andreas Roeseler
Modify the icmp_rcv function to check PROBE messages and call icmp_echo
if a PROBE request is detected.
Modify the existing icmp_echo function to respond ot both ping and PROBE
requests.
This was tested using a custom modification to the iputils package and
wireshark. It supports IPV4 probing by name, ifindex, and probing by
both IPV4 and IPV6 addresses. It currently does not support responding
to probes off the proxy node (see RFC 8335 Section 2).
Signed-off-by: Andreas Roeseler <andreas.a.roeseler@gmail.com>
---
Changes:
v1 -> v2:
- Reorder variable declarations to follow coding style
- Switch to functions such as dev_get_by_name and ip_dev_find to lookup
net devices
v2 -> v3:
Suggested by Willem de Bruijn <willemdebruijn.kernel@gmail.com>
- Add verification of incoming messages before looking up netdev
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
- Include net/addrconf.h library for ipv6_dev_find
v3 -> v4:
Suggested by Willem de Bruijn <willemdebruijn.kernel@gmail.com>
- Use skb_header_pointer to verify fields in incoming message
- Add check to ensure that extobj_hdr.length is valid
- Check to ensure object payload is padded with ASCII NULL characters
when probing by name, as specified by RFC 8335
- Statically allocate buff using IFNAMSIZ
- Add rcu blocking around ipv6_dev_find
- Use __in_dev_get_rcu to access IPV4 addresses of identified
net_device
- Remove check for ICMPV6 PROBE types
---
net/ipv4/icmp.c | 145 +++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 130 insertions(+), 15 deletions(-)
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index 616e2dc1c8fa..f1530011b7bc 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -93,6 +93,10 @@
#include <net/ip_fib.h>
#include <net/l3mdev.h>
+#if IS_ENABLED(CONFIG_IPV6)
+#include <net/addrconf.h>
+#endif
+
/*
* Build xmit assembly blocks
*/
@@ -971,7 +975,7 @@ static bool icmp_redirect(struct sk_buff *skb)
}
/*
- * Handle ICMP_ECHO ("ping") requests.
+ * Handle ICMP_ECHO ("ping") and ICMP_EXT_ECHO ("PROBE") requests.
*
* RFC 1122: 3.2.2.6 MUST have an echo server that answers ICMP echo
* requests.
@@ -979,27 +983,127 @@ static bool icmp_redirect(struct sk_buff *skb)
* included in the reply.
* RFC 1812: 4.3.3.6 SHOULD have a config option for silently ignoring
* echo requests, MUST have default=NOT.
+ * RFC 8335: 8 MUST have a config option to enable/disable ICMP
+ * Extended Echo Functionality, MUST be disabled by default
* See also WRT handling of options once they are done and working.
*/
static bool icmp_echo(struct sk_buff *skb)
{
+ struct icmp_ext_hdr *ext_hdr, _ext_hdr;
+ struct icmp_ext_echo_iio *iio, _iio;
+ struct icmp_bxm icmp_param;
+ struct net_device *dev;
struct net *net;
+ u16 ident_len;
+ char *buff;
+ u8 status;
net = dev_net(skb_dst(skb)->dev);
- if (!net->ipv4.sysctl_icmp_echo_ignore_all) {
- struct icmp_bxm icmp_param;
-
- icmp_param.data.icmph = *icmp_hdr(skb);
- icmp_param.data.icmph.type = ICMP_ECHOREPLY;
- icmp_param.skb = skb;
- icmp_param.offset = 0;
- icmp_param.data_len = skb->len;
- icmp_param.head_len = sizeof(struct icmphdr);
- icmp_reply(&icmp_param, skb);
- }
/* should there be an ICMP stat for ignored echos? */
- return true;
+ if (net->ipv4.sysctl_icmp_echo_ignore_all)
+ return true;
+
+ icmp_param.data.icmph = *icmp_hdr(skb);
+ icmp_param.skb = skb;
+ icmp_param.offset = 0;
+ icmp_param.data_len = skb->len;
+ icmp_param.head_len = sizeof(struct icmphdr);
+
+ if (icmp_param.data.icmph.type == ICMP_ECHO)
+ goto send_reply;
+ if (!net->ipv4.sysctl_icmp_echo_enable_probe)
+ return true;
+ /* We currently only support probing interfaces on the proxy node
+ * Check to ensure L-bit is set
+ */
+ if (!(ntohs(icmp_param.data.icmph.un.echo.sequence) & 1))
+ return true;
+ /* Clear status bits in reply message */
+ icmp_param.data.icmph.un.echo.sequence &= htons(0xFF00);
+ icmp_param.data.icmph.type = ICMP_EXT_ECHOREPLY;
+ ext_hdr = skb_header_pointer(skb, 0, sizeof(_ext_hdr), &_ext_hdr);
+ iio = skb_header_pointer(skb, sizeof(_ext_hdr), sizeof(_iio), &_iio);
+ if (!ext_hdr || !iio)
+ goto send_mal_query;
+ if (ntohs(iio->extobj_hdr.length) <= sizeof(iio->extobj_hdr))
+ goto send_mal_query;
+ ident_len = ntohs(iio->extobj_hdr.length) - sizeof(iio->extobj_hdr);
+ status = 0;
+ dev = NULL;
+ switch (iio->extobj_hdr.class_type) {
+ case EXT_ECHO_CTYPE_NAME:
+ if (ident_len >= IFNAMSIZ)
+ goto send_mal_query;
+ buff = kcalloc(IFNAMSIZ, sizeof(char), GFP_KERNEL);
+ if (!buff)
+ return -ENOMEM;
+ memcpy(buff, &iio->ident.name, ident_len);
+ /* RFC 8335 2.1 If the Object Payload would not otherwise terminate
+ * on a 32-bit boundary, it MUST be padded with ASCII NULL characters
+ */
+ if (ident_len % sizeof(u32) != 0) {
+ u8 i;
+
+ for (i = ident_len; i % sizeof(u32) != 0; i++) {
+ if (buff[i] != '\0')
+ goto send_mal_query;
+ }
+ }
+ dev = dev_get_by_name(net, buff);
+ kfree(buff);
+ break;
+ case EXT_ECHO_CTYPE_INDEX:
+ if (ident_len != sizeof(iio->ident.ifindex))
+ goto send_mal_query;
+ dev = dev_get_by_index(net, ntohl(iio->ident.ifindex));
+ break;
+ case EXT_ECHO_CTYPE_ADDR:
+ if (ident_len != sizeof(iio->ident.addr.ctype3_hdr) + iio->ident.addr.ctype3_hdr.addrlen)
+ goto send_mal_query;
+ switch (ntohs(iio->ident.addr.ctype3_hdr.afi)) {
+ case ICMP_AFI_IP:
+ if (ident_len != sizeof(iio->ident.addr.ctype3_hdr) + sizeof(struct in_addr))
+ goto send_mal_query;
+ dev = ip_dev_find(net, iio->ident.addr.ip_addr.ipv4_addr.s_addr);
+ break;
+#if IS_ENABLED(CONFIG_IPV6)
+ case ICMP_AFI_IP6:
+ if (ident_len != sizeof(iio->ident.addr.ctype3_hdr) + sizeof(struct in6_addr))
+ goto send_mal_query;
+ rcu_read_lock();
+ dev = ipv6_dev_find(net, &iio->ident.addr.ip_addr.ipv6_addr, dev);
+ if (dev)
+ dev_hold(dev);
+ rcu_read_unlock();
+ break;
+#endif
+ default:
+ goto send_mal_query;
+ }
+ break;
+ default:
+ goto send_mal_query;
+ }
+ if (!dev) {
+ icmp_param.data.icmph.code = ICMP_EXT_NO_IF;
+ goto send_reply;
+ }
+ /* Fill bits in reply message */
+ if (dev->flags & IFF_UP)
+ status |= EXT_ECHOREPLY_ACTIVE;
+ if (__in_dev_get_rcu(dev) && __in_dev_get_rcu(dev)->ifa_list)
+ status |= EXT_ECHOREPLY_IPV4;
+ if (!list_empty(&dev->ip6_ptr->addr_list))
+ status |= EXT_ECHOREPLY_IPV6;
+ dev_put(dev);
+ icmp_param.data.icmph.un.echo.sequence |= htons(status);
+send_reply:
+ icmp_reply(&icmp_param, skb);
+ return true;
+send_mal_query:
+ icmp_param.data.icmph.code = ICMP_EXT_MAL_QUERY;
+ goto send_reply;
}
/*
@@ -1088,6 +1192,11 @@ int icmp_rcv(struct sk_buff *skb)
icmph = icmp_hdr(skb);
ICMPMSGIN_INC_STATS(net, icmph->type);
+
+ /* Check for ICMP Extended Echo (PROBE) messages */
+ if (icmph->type == ICMP_EXT_ECHO)
+ goto probe;
+
/*
* 18 is the highest 'known' ICMP type. Anything else is a mystery
*
@@ -1097,7 +1206,6 @@ int icmp_rcv(struct sk_buff *skb)
if (icmph->type > NR_ICMP_TYPES)
goto error;
-
/*
* Parse the ICMP message
*/
@@ -1123,7 +1231,7 @@ int icmp_rcv(struct sk_buff *skb)
}
success = icmp_pointers[icmph->type].handler(skb);
-
+success_check:
if (success) {
consume_skb(skb);
return NET_RX_SUCCESS;
@@ -1137,6 +1245,12 @@ int icmp_rcv(struct sk_buff *skb)
error:
__ICMP_INC_STATS(net, ICMP_MIB_INERRORS);
goto drop;
+probe:
+ /* We can't use icmp_pointers[].handler() because it is an array of
+ * size NR_ICMP_TYPES + 1 (19 elements) and PROBE has code 42.
+ */
+ success = icmp_echo(skb);
+ goto success_check;
}
static bool ip_icmp_error_rfc4884_validate(const struct sk_buff *skb, int off)
@@ -1340,6 +1454,7 @@ static int __net_init icmp_sk_init(struct net *net)
/* Control parameters for ECHO replies. */
net->ipv4.sysctl_icmp_echo_ignore_all = 0;
+ net->ipv4.sysctl_icmp_echo_enable_probe = 0;
net->ipv4.sysctl_icmp_echo_ignore_broadcasts = 1;
/* Control parameter - ignore bogus broadcast responses? */
--
2.17.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH V4 net-next 5/5] icmp: add response to RFC 8335 PROBE messages
2021-03-14 16:48 ` [PATCH V4 net-next 5/5] icmp: add response to " Andreas Roeseler
@ 2021-03-14 17:59 ` kernel test robot
2021-03-14 18:32 ` kernel test robot
` (3 subsequent siblings)
4 siblings, 0 replies; 18+ messages in thread
From: kernel test robot @ 2021-03-14 17:59 UTC (permalink / raw)
To: kbuild-all
[-- Attachment #1: Type: text/plain, Size: 7966 bytes --]
Hi Andreas,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on net-next/master]
url: https://github.com/0day-ci/linux/commits/Andreas-Roeseler/add-support-for-RFC-8335-PROBE/20210315-005052
base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 6f1629093399303bf19d6fcd5144061d1e25ec23
config: i386-randconfig-s032-20210314 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.3-262-g5e674421-dirty
# https://github.com/0day-ci/linux/commit/54d9928f1734e7b3511b945a2ce912b931a07776
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Andreas-Roeseler/add-support-for-RFC-8335-PROBE/20210315-005052
git checkout 54d9928f1734e7b3511b945a2ce912b931a07776
# save the attached .config to linux build tree
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
"sparse warnings: (new ones prefixed by >>)"
>> net/ipv4/icmp.c:1059:45: sparse: sparse: cast to restricted __be32
>> net/ipv4/icmp.c:1059:45: sparse: sparse: cast to restricted __be32
>> net/ipv4/icmp.c:1059:45: sparse: sparse: cast to restricted __be32
>> net/ipv4/icmp.c:1059:45: sparse: sparse: cast to restricted __be32
>> net/ipv4/icmp.c:1059:45: sparse: sparse: cast to restricted __be32
>> net/ipv4/icmp.c:1059:45: sparse: sparse: cast to restricted __be32
>> net/ipv4/icmp.c:1064:25: sparse: sparse: cast to restricted __be16
>> net/ipv4/icmp.c:1064:25: sparse: sparse: cast to restricted __be16
>> net/ipv4/icmp.c:1064:25: sparse: sparse: cast to restricted __be16
>> net/ipv4/icmp.c:1064:25: sparse: sparse: cast to restricted __be16
>> net/ipv4/icmp.c:1097:29: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct list_head const *head @@ got struct list_head [noderef] __rcu * @@
net/ipv4/icmp.c:1097:29: sparse: expected struct list_head const *head
net/ipv4/icmp.c:1097:29: sparse: got struct list_head [noderef] __rcu *
net/ipv4/icmp.c: note: in included file (through include/linux/spinlock.h, include/linux/mmzone.h, include/linux/gfp.h, ...):
include/linux/bottom_half.h:32:30: sparse: sparse: context imbalance in 'icmp_reply' - different lock contexts for basic block
include/linux/bottom_half.h:32:30: sparse: sparse: context imbalance in '__icmp_send' - different lock contexts for basic block
vim +1059 net/ipv4/icmp.c
976
977 /*
978 * Handle ICMP_ECHO ("ping") and ICMP_EXT_ECHO ("PROBE") requests.
979 *
980 * RFC 1122: 3.2.2.6 MUST have an echo server that answers ICMP echo
981 * requests.
982 * RFC 1122: 3.2.2.6 Data received in the ICMP_ECHO request MUST be
983 * included in the reply.
984 * RFC 1812: 4.3.3.6 SHOULD have a config option for silently ignoring
985 * echo requests, MUST have default=NOT.
986 * RFC 8335: 8 MUST have a config option to enable/disable ICMP
987 * Extended Echo Functionality, MUST be disabled by default
988 * See also WRT handling of options once they are done and working.
989 */
990
991 static bool icmp_echo(struct sk_buff *skb)
992 {
993 struct icmp_ext_hdr *ext_hdr, _ext_hdr;
994 struct icmp_ext_echo_iio *iio, _iio;
995 struct icmp_bxm icmp_param;
996 struct net_device *dev;
997 struct net *net;
998 u16 ident_len;
999 char *buff;
1000 u8 status;
1001
1002 net = dev_net(skb_dst(skb)->dev);
1003 /* should there be an ICMP stat for ignored echos? */
1004 if (net->ipv4.sysctl_icmp_echo_ignore_all)
1005 return true;
1006
1007 icmp_param.data.icmph = *icmp_hdr(skb);
1008 icmp_param.skb = skb;
1009 icmp_param.offset = 0;
1010 icmp_param.data_len = skb->len;
1011 icmp_param.head_len = sizeof(struct icmphdr);
1012
1013 if (icmp_param.data.icmph.type == ICMP_ECHO)
1014 goto send_reply;
1015 if (!net->ipv4.sysctl_icmp_echo_enable_probe)
1016 return true;
1017 /* We currently only support probing interfaces on the proxy node
1018 * Check to ensure L-bit is set
1019 */
1020 if (!(ntohs(icmp_param.data.icmph.un.echo.sequence) & 1))
1021 return true;
1022 /* Clear status bits in reply message */
1023 icmp_param.data.icmph.un.echo.sequence &= htons(0xFF00);
1024 icmp_param.data.icmph.type = ICMP_EXT_ECHOREPLY;
1025 ext_hdr = skb_header_pointer(skb, 0, sizeof(_ext_hdr), &_ext_hdr);
1026 iio = skb_header_pointer(skb, sizeof(_ext_hdr), sizeof(_iio), &_iio);
1027 if (!ext_hdr || !iio)
1028 goto send_mal_query;
1029 if (ntohs(iio->extobj_hdr.length) <= sizeof(iio->extobj_hdr))
1030 goto send_mal_query;
1031 ident_len = ntohs(iio->extobj_hdr.length) - sizeof(iio->extobj_hdr);
1032 status = 0;
1033 dev = NULL;
1034 switch (iio->extobj_hdr.class_type) {
1035 case EXT_ECHO_CTYPE_NAME:
1036 if (ident_len >= IFNAMSIZ)
1037 goto send_mal_query;
1038 buff = kcalloc(IFNAMSIZ, sizeof(char), GFP_KERNEL);
1039 if (!buff)
1040 return -ENOMEM;
1041 memcpy(buff, &iio->ident.name, ident_len);
1042 /* RFC 8335 2.1 If the Object Payload would not otherwise terminate
1043 * on a 32-bit boundary, it MUST be padded with ASCII NULL characters
1044 */
1045 if (ident_len % sizeof(u32) != 0) {
1046 u8 i;
1047
1048 for (i = ident_len; i % sizeof(u32) != 0; i++) {
1049 if (buff[i] != '\0')
1050 goto send_mal_query;
1051 }
1052 }
1053 dev = dev_get_by_name(net, buff);
1054 kfree(buff);
1055 break;
1056 case EXT_ECHO_CTYPE_INDEX:
1057 if (ident_len != sizeof(iio->ident.ifindex))
1058 goto send_mal_query;
> 1059 dev = dev_get_by_index(net, ntohl(iio->ident.ifindex));
1060 break;
1061 case EXT_ECHO_CTYPE_ADDR:
1062 if (ident_len != sizeof(iio->ident.addr.ctype3_hdr) + iio->ident.addr.ctype3_hdr.addrlen)
1063 goto send_mal_query;
> 1064 switch (ntohs(iio->ident.addr.ctype3_hdr.afi)) {
1065 case ICMP_AFI_IP:
1066 if (ident_len != sizeof(iio->ident.addr.ctype3_hdr) + sizeof(struct in_addr))
1067 goto send_mal_query;
1068 dev = ip_dev_find(net, iio->ident.addr.ip_addr.ipv4_addr.s_addr);
1069 break;
1070 #if IS_ENABLED(CONFIG_IPV6)
1071 case ICMP_AFI_IP6:
1072 if (ident_len != sizeof(iio->ident.addr.ctype3_hdr) + sizeof(struct in6_addr))
1073 goto send_mal_query;
1074 rcu_read_lock();
1075 dev = ipv6_dev_find(net, &iio->ident.addr.ip_addr.ipv6_addr, dev);
1076 if (dev)
1077 dev_hold(dev);
1078 rcu_read_unlock();
1079 break;
1080 #endif
1081 default:
1082 goto send_mal_query;
1083 }
1084 break;
1085 default:
1086 goto send_mal_query;
1087 }
1088 if (!dev) {
1089 icmp_param.data.icmph.code = ICMP_EXT_NO_IF;
1090 goto send_reply;
1091 }
1092 /* Fill bits in reply message */
1093 if (dev->flags & IFF_UP)
1094 status |= EXT_ECHOREPLY_ACTIVE;
1095 if (__in_dev_get_rcu(dev) && __in_dev_get_rcu(dev)->ifa_list)
1096 status |= EXT_ECHOREPLY_IPV4;
> 1097 if (!list_empty(&dev->ip6_ptr->addr_list))
1098 status |= EXT_ECHOREPLY_IPV6;
1099 dev_put(dev);
1100 icmp_param.data.icmph.un.echo.sequence |= htons(status);
1101 send_reply:
1102 icmp_reply(&icmp_param, skb);
1103 return true;
1104 send_mal_query:
1105 icmp_param.data.icmph.code = ICMP_EXT_MAL_QUERY;
1106 goto send_reply;
1107 }
1108
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 36672 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH V4 net-next 5/5] icmp: add response to RFC 8335 PROBE messages
2021-03-14 16:48 ` [PATCH V4 net-next 5/5] icmp: add response to " Andreas Roeseler
2021-03-14 17:59 ` kernel test robot
@ 2021-03-14 18:32 ` kernel test robot
2021-03-14 18:33 ` kernel test robot
` (2 subsequent siblings)
4 siblings, 0 replies; 18+ messages in thread
From: kernel test robot @ 2021-03-14 18:32 UTC (permalink / raw)
To: kbuild-all
[-- Attachment #1: Type: text/plain, Size: 5989 bytes --]
Hi Andreas,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on net-next/master]
url: https://github.com/0day-ci/linux/commits/Andreas-Roeseler/add-support-for-RFC-8335-PROBE/20210315-005052
base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 6f1629093399303bf19d6fcd5144061d1e25ec23
config: x86_64-randconfig-m001-20210314 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
smatch warnings:
net/ipv4/icmp.c:1040 icmp_echo() warn: signedness bug returning '(-12)'
vim +1040 net/ipv4/icmp.c
976
977 /*
978 * Handle ICMP_ECHO ("ping") and ICMP_EXT_ECHO ("PROBE") requests.
979 *
980 * RFC 1122: 3.2.2.6 MUST have an echo server that answers ICMP echo
981 * requests.
982 * RFC 1122: 3.2.2.6 Data received in the ICMP_ECHO request MUST be
983 * included in the reply.
984 * RFC 1812: 4.3.3.6 SHOULD have a config option for silently ignoring
985 * echo requests, MUST have default=NOT.
986 * RFC 8335: 8 MUST have a config option to enable/disable ICMP
987 * Extended Echo Functionality, MUST be disabled by default
988 * See also WRT handling of options once they are done and working.
989 */
990
991 static bool icmp_echo(struct sk_buff *skb)
992 {
993 struct icmp_ext_hdr *ext_hdr, _ext_hdr;
994 struct icmp_ext_echo_iio *iio, _iio;
995 struct icmp_bxm icmp_param;
996 struct net_device *dev;
997 struct net *net;
998 u16 ident_len;
999 char *buff;
1000 u8 status;
1001
1002 net = dev_net(skb_dst(skb)->dev);
1003 /* should there be an ICMP stat for ignored echos? */
1004 if (net->ipv4.sysctl_icmp_echo_ignore_all)
1005 return true;
1006
1007 icmp_param.data.icmph = *icmp_hdr(skb);
1008 icmp_param.skb = skb;
1009 icmp_param.offset = 0;
1010 icmp_param.data_len = skb->len;
1011 icmp_param.head_len = sizeof(struct icmphdr);
1012
1013 if (icmp_param.data.icmph.type == ICMP_ECHO)
1014 goto send_reply;
1015 if (!net->ipv4.sysctl_icmp_echo_enable_probe)
1016 return true;
1017 /* We currently only support probing interfaces on the proxy node
1018 * Check to ensure L-bit is set
1019 */
1020 if (!(ntohs(icmp_param.data.icmph.un.echo.sequence) & 1))
1021 return true;
1022 /* Clear status bits in reply message */
1023 icmp_param.data.icmph.un.echo.sequence &= htons(0xFF00);
1024 icmp_param.data.icmph.type = ICMP_EXT_ECHOREPLY;
1025 ext_hdr = skb_header_pointer(skb, 0, sizeof(_ext_hdr), &_ext_hdr);
1026 iio = skb_header_pointer(skb, sizeof(_ext_hdr), sizeof(_iio), &_iio);
1027 if (!ext_hdr || !iio)
1028 goto send_mal_query;
1029 if (ntohs(iio->extobj_hdr.length) <= sizeof(iio->extobj_hdr))
1030 goto send_mal_query;
1031 ident_len = ntohs(iio->extobj_hdr.length) - sizeof(iio->extobj_hdr);
1032 status = 0;
1033 dev = NULL;
1034 switch (iio->extobj_hdr.class_type) {
1035 case EXT_ECHO_CTYPE_NAME:
1036 if (ident_len >= IFNAMSIZ)
1037 goto send_mal_query;
1038 buff = kcalloc(IFNAMSIZ, sizeof(char), GFP_KERNEL);
1039 if (!buff)
> 1040 return -ENOMEM;
1041 memcpy(buff, &iio->ident.name, ident_len);
1042 /* RFC 8335 2.1 If the Object Payload would not otherwise terminate
1043 * on a 32-bit boundary, it MUST be padded with ASCII NULL characters
1044 */
1045 if (ident_len % sizeof(u32) != 0) {
1046 u8 i;
1047
1048 for (i = ident_len; i % sizeof(u32) != 0; i++) {
1049 if (buff[i] != '\0')
1050 goto send_mal_query;
1051 }
1052 }
1053 dev = dev_get_by_name(net, buff);
1054 kfree(buff);
1055 break;
1056 case EXT_ECHO_CTYPE_INDEX:
1057 if (ident_len != sizeof(iio->ident.ifindex))
1058 goto send_mal_query;
1059 dev = dev_get_by_index(net, ntohl(iio->ident.ifindex));
1060 break;
1061 case EXT_ECHO_CTYPE_ADDR:
1062 if (ident_len != sizeof(iio->ident.addr.ctype3_hdr) + iio->ident.addr.ctype3_hdr.addrlen)
1063 goto send_mal_query;
1064 switch (ntohs(iio->ident.addr.ctype3_hdr.afi)) {
1065 case ICMP_AFI_IP:
1066 if (ident_len != sizeof(iio->ident.addr.ctype3_hdr) + sizeof(struct in_addr))
1067 goto send_mal_query;
1068 dev = ip_dev_find(net, iio->ident.addr.ip_addr.ipv4_addr.s_addr);
1069 break;
1070 #if IS_ENABLED(CONFIG_IPV6)
1071 case ICMP_AFI_IP6:
1072 if (ident_len != sizeof(iio->ident.addr.ctype3_hdr) + sizeof(struct in6_addr))
1073 goto send_mal_query;
1074 rcu_read_lock();
1075 dev = ipv6_dev_find(net, &iio->ident.addr.ip_addr.ipv6_addr, dev);
1076 if (dev)
1077 dev_hold(dev);
1078 rcu_read_unlock();
1079 break;
1080 #endif
1081 default:
1082 goto send_mal_query;
1083 }
1084 break;
1085 default:
1086 goto send_mal_query;
1087 }
1088 if (!dev) {
1089 icmp_param.data.icmph.code = ICMP_EXT_NO_IF;
1090 goto send_reply;
1091 }
1092 /* Fill bits in reply message */
1093 if (dev->flags & IFF_UP)
1094 status |= EXT_ECHOREPLY_ACTIVE;
1095 if (__in_dev_get_rcu(dev) && __in_dev_get_rcu(dev)->ifa_list)
1096 status |= EXT_ECHOREPLY_IPV4;
1097 if (!list_empty(&dev->ip6_ptr->addr_list))
1098 status |= EXT_ECHOREPLY_IPV6;
1099 dev_put(dev);
1100 icmp_param.data.icmph.un.echo.sequence |= htons(status);
1101 send_reply:
1102 icmp_reply(&icmp_param, skb);
1103 return true;
1104 send_mal_query:
1105 icmp_param.data.icmph.code = ICMP_EXT_MAL_QUERY;
1106 goto send_reply;
1107 }
1108
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 34771 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH V4 net-next 5/5] icmp: add response to RFC 8335 PROBE messages
2021-03-14 16:48 ` [PATCH V4 net-next 5/5] icmp: add response to " Andreas Roeseler
2021-03-14 17:59 ` kernel test robot
2021-03-14 18:32 ` kernel test robot
@ 2021-03-14 18:33 ` kernel test robot
2021-03-14 20:35 ` kernel test robot
2021-03-15 15:50 ` Willem de Bruijn
4 siblings, 0 replies; 18+ messages in thread
From: kernel test robot @ 2021-03-14 18:33 UTC (permalink / raw)
To: kbuild-all
[-- Attachment #1: Type: text/plain, Size: 1627 bytes --]
Hi Andreas,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on net-next/master]
url: https://github.com/0day-ci/linux/commits/Andreas-Roeseler/add-support-for-RFC-8335-PROBE/20210315-005052
base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 6f1629093399303bf19d6fcd5144061d1e25ec23
config: openrisc-randconfig-r005-20210314 (attached as .config)
compiler: or1k-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/54d9928f1734e7b3511b945a2ce912b931a07776
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Andreas-Roeseler/add-support-for-RFC-8335-PROBE/20210315-005052
git checkout 54d9928f1734e7b3511b945a2ce912b931a07776
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=openrisc
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
or1k-linux-ld: net/ipv4/icmp.o: in function `icmp_echo.part.0':
>> icmp.c:(.text+0x19ec): undefined reference to `ipv6_dev_find'
icmp.c:(.text+0x19ec): relocation truncated to fit: R_OR1K_INSN_REL_26 against undefined symbol `ipv6_dev_find'
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 25651 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH V4 net-next 5/5] icmp: add response to RFC 8335 PROBE messages
2021-03-14 16:48 ` [PATCH V4 net-next 5/5] icmp: add response to " Andreas Roeseler
` (2 preceding siblings ...)
2021-03-14 18:33 ` kernel test robot
@ 2021-03-14 20:35 ` kernel test robot
2021-03-18 3:11 ` Andreas Roeseler
2021-03-15 15:50 ` Willem de Bruijn
4 siblings, 1 reply; 18+ messages in thread
From: kernel test robot @ 2021-03-14 20:35 UTC (permalink / raw)
To: kbuild-all
[-- Attachment #1: Type: text/plain, Size: 1493 bytes --]
Hi Andreas,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on net-next/master]
url: https://github.com/0day-ci/linux/commits/Andreas-Roeseler/add-support-for-RFC-8335-PROBE/20210315-005052
base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 6f1629093399303bf19d6fcd5144061d1e25ec23
config: mips-allmodconfig (attached as .config)
compiler: mips-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/54d9928f1734e7b3511b945a2ce912b931a07776
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Andreas-Roeseler/add-support-for-RFC-8335-PROBE/20210315-005052
git checkout 54d9928f1734e7b3511b945a2ce912b931a07776
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=mips
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
mips-linux-ld: net/ipv4/icmp.o: in function `icmp_echo':
>> icmp.c:(.text.icmp_echo+0x658): undefined reference to `ipv6_dev_find'
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 70112 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH V4 net-next 5/5] icmp: add response to RFC 8335 PROBE messages
2021-03-14 16:48 ` [PATCH V4 net-next 5/5] icmp: add response to " Andreas Roeseler
` (3 preceding siblings ...)
2021-03-14 20:35 ` kernel test robot
@ 2021-03-15 15:50 ` Willem de Bruijn
2021-03-15 19:09 ` Andreas Roeseler
4 siblings, 1 reply; 18+ messages in thread
From: Willem de Bruijn @ 2021-03-15 15:50 UTC (permalink / raw)
To: Andreas Roeseler
Cc: David Miller, Hideaki YOSHIFUJI, David Ahern, Jakub Kicinski,
Network Development
On Sun, Mar 14, 2021 at 12:50 PM Andreas Roeseler
<andreas.a.roeseler@gmail.com> wrote:
>
> Modify the icmp_rcv function to check PROBE messages and call icmp_echo
> if a PROBE request is detected.
>
> Modify the existing icmp_echo function to respond ot both ping and PROBE
> requests.
>
> This was tested using a custom modification to the iputils package and
> wireshark. It supports IPV4 probing by name, ifindex, and probing by
> both IPV4 and IPV6 addresses. It currently does not support responding
> to probes off the proxy node (see RFC 8335 Section 2).
If you happen to use github or something similar, if you don't mind
sharing the code, you could clone the iputils repo and publish the
changes. No pressure.
> net/ipv4/icmp.c | 145 +++++++++++++++++++++++++++++++++++++++++++-----
> 1 file changed, 130 insertions(+), 15 deletions(-)
>
> diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
> index 616e2dc1c8fa..f1530011b7bc 100644
> --- a/net/ipv4/icmp.c
> +++ b/net/ipv4/icmp.c
> @@ -93,6 +93,10 @@
> #include <net/ip_fib.h>
> #include <net/l3mdev.h>
>
> +#if IS_ENABLED(CONFIG_IPV6)
> +#include <net/addrconf.h>
> +#endif
I don't think the conditional is needed (?)
> static bool icmp_echo(struct sk_buff *skb)
> {
> + struct icmp_ext_hdr *ext_hdr, _ext_hdr;
> + struct icmp_ext_echo_iio *iio, _iio;
> + struct icmp_bxm icmp_param;
> + struct net_device *dev;
> struct net *net;
> + u16 ident_len;
> + char *buff;
> + u8 status;
>
> net = dev_net(skb_dst(skb)->dev);
> - if (!net->ipv4.sysctl_icmp_echo_ignore_all) {
> - struct icmp_bxm icmp_param;
> -
> - icmp_param.data.icmph = *icmp_hdr(skb);
> - icmp_param.data.icmph.type = ICMP_ECHOREPLY;
> - icmp_param.skb = skb;
> - icmp_param.offset = 0;
> - icmp_param.data_len = skb->len;
> - icmp_param.head_len = sizeof(struct icmphdr);
> - icmp_reply(&icmp_param, skb);
> - }
> /* should there be an ICMP stat for ignored echos? */
> - return true;
> + if (net->ipv4.sysctl_icmp_echo_ignore_all)
> + return true;
> +
> + icmp_param.data.icmph = *icmp_hdr(skb);
> + icmp_param.skb = skb;
> + icmp_param.offset = 0;
> + icmp_param.data_len = skb->len;
> + icmp_param.head_len = sizeof(struct icmphdr);
> +
> + if (icmp_param.data.icmph.type == ICMP_ECHO)
> + goto send_reply;
Is this path now missing
icmp_param.data.icmph.type = ICMP_ECHOREPLY;
> + if (!net->ipv4.sysctl_icmp_echo_enable_probe)
> + return true;
> + /* We currently only support probing interfaces on the proxy node
> + * Check to ensure L-bit is set
> + */
> + if (!(ntohs(icmp_param.data.icmph.un.echo.sequence) & 1))
> + return true;
> + /* Clear status bits in reply message */
> + icmp_param.data.icmph.un.echo.sequence &= htons(0xFF00);
> + icmp_param.data.icmph.type = ICMP_EXT_ECHOREPLY;
> + ext_hdr = skb_header_pointer(skb, 0, sizeof(_ext_hdr), &_ext_hdr);
> + iio = skb_header_pointer(skb, sizeof(_ext_hdr), sizeof(_iio), &_iio);
> + if (!ext_hdr || !iio)
> + goto send_mal_query;
> + if (ntohs(iio->extobj_hdr.length) <= sizeof(iio->extobj_hdr))
> + goto send_mal_query;
> + ident_len = ntohs(iio->extobj_hdr.length) - sizeof(iio->extobj_hdr);
> + status = 0;
> + dev = NULL;
> + switch (iio->extobj_hdr.class_type) {
> + case EXT_ECHO_CTYPE_NAME:
> + if (ident_len >= IFNAMSIZ)
> + goto send_mal_query;
> + buff = kcalloc(IFNAMSIZ, sizeof(char), GFP_KERNEL);
> + if (!buff)
> + return -ENOMEM;
> + memcpy(buff, &iio->ident.name, ident_len);
> + /* RFC 8335 2.1 If the Object Payload would not otherwise terminate
> + * on a 32-bit boundary, it MUST be padded with ASCII NULL characters
> + */
> + if (ident_len % sizeof(u32) != 0) {
> + u8 i;
> +
> + for (i = ident_len; i % sizeof(u32) != 0; i++) {
> + if (buff[i] != '\0')
> + goto send_mal_query;
Memory leak. IFNAMSIZ is small enough that you can use on-stack allocation
Also, I think you can ignore if there are non-zero bytes beyond the
len. We need to safely parse to avoid integrity bugs in the kernel.
Beyond that, it's fine to be strict about what you send, liberal what
you accept.
> + }
> + }
> + dev = dev_get_by_name(net, buff);
> + kfree(buff);
> + break;
> + case EXT_ECHO_CTYPE_INDEX:
> + if (ident_len != sizeof(iio->ident.ifindex))
> + goto send_mal_query;
> + dev = dev_get_by_index(net, ntohl(iio->ident.ifindex));
> + break;
> + case EXT_ECHO_CTYPE_ADDR:
> + if (ident_len != sizeof(iio->ident.addr.ctype3_hdr) + iio->ident.addr.ctype3_hdr.addrlen)
> + goto send_mal_query;
> + switch (ntohs(iio->ident.addr.ctype3_hdr.afi)) {
> + case ICMP_AFI_IP:
> + if (ident_len != sizeof(iio->ident.addr.ctype3_hdr) + sizeof(struct in_addr))
> + goto send_mal_query;
> + dev = ip_dev_find(net, iio->ident.addr.ip_addr.ipv4_addr.s_addr);
> + break;
> +#if IS_ENABLED(CONFIG_IPV6)
> + case ICMP_AFI_IP6:
> + if (ident_len != sizeof(iio->ident.addr.ctype3_hdr) + sizeof(struct in6_addr))
> + goto send_mal_query;
> + rcu_read_lock();
> + dev = ipv6_dev_find(net, &iio->ident.addr.ip_addr.ipv6_addr, dev);
> + if (dev)
> + dev_hold(dev);
> + rcu_read_unlock();
> + break;
> +#endif
> + default:
> + goto send_mal_query;
> + }
> + break;
> + default:
> + goto send_mal_query;
> + }
> + if (!dev) {
> + icmp_param.data.icmph.code = ICMP_EXT_NO_IF;
> + goto send_reply;
> + }
> + /* Fill bits in reply message */
> + if (dev->flags & IFF_UP)
> + status |= EXT_ECHOREPLY_ACTIVE;
> + if (__in_dev_get_rcu(dev) && __in_dev_get_rcu(dev)->ifa_list)
> + status |= EXT_ECHOREPLY_IPV4;
> + if (!list_empty(&dev->ip6_ptr->addr_list))
> + status |= EXT_ECHOREPLY_IPV6;
> + dev_put(dev);
> + icmp_param.data.icmph.un.echo.sequence |= htons(status);
> +send_reply:
> + icmp_reply(&icmp_param, skb);
> + return true;
> +send_mal_query:
> + icmp_param.data.icmph.code = ICMP_EXT_MAL_QUERY;
> + goto send_reply;
> }
>
> /*
> @@ -1088,6 +1192,11 @@ int icmp_rcv(struct sk_buff *skb)
> icmph = icmp_hdr(skb);
>
> ICMPMSGIN_INC_STATS(net, icmph->type);
> +
> + /* Check for ICMP Extended Echo (PROBE) messages */
> + if (icmph->type == ICMP_EXT_ECHO)
> + goto probe;
> +
> /*
> * 18 is the highest 'known' ICMP type. Anything else is a mystery
> *
> @@ -1097,7 +1206,6 @@ int icmp_rcv(struct sk_buff *skb)
> if (icmph->type > NR_ICMP_TYPES)
> goto error;
>
> -
> /*
> * Parse the ICMP message
> */
> @@ -1123,7 +1231,7 @@ int icmp_rcv(struct sk_buff *skb)
> }
>
> success = icmp_pointers[icmph->type].handler(skb);
> -
> +success_check:
> if (success) {
> consume_skb(skb);
> return NET_RX_SUCCESS;
> @@ -1137,6 +1245,12 @@ int icmp_rcv(struct sk_buff *skb)
> error:
> __ICMP_INC_STATS(net, ICMP_MIB_INERRORS);
> goto drop;
> +probe:
> + /* We can't use icmp_pointers[].handler() because it is an array of
> + * size NR_ICMP_TYPES + 1 (19 elements) and PROBE has code 42.
> + */
> + success = icmp_echo(skb);
> + goto success_check;
just make this a branch instead of
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH V4 net-next 5/5] icmp: add response to RFC 8335 PROBE messages
2021-03-15 15:50 ` Willem de Bruijn
@ 2021-03-15 19:09 ` Andreas Roeseler
2021-03-15 19:34 ` Willem de Bruijn
0 siblings, 1 reply; 18+ messages in thread
From: Andreas Roeseler @ 2021-03-15 19:09 UTC (permalink / raw)
To: Willem de Bruijn
Cc: David Miller, Hideaki YOSHIFUJI, David Ahern, Jakub Kicinski,
Network Development
On Mon, 2021-03-15 at 11:50 -0400, Willem de Bruijn wrote:
> On Sun, Mar 14, 2021 at 12:50 PM Andreas Roeseler
> <andreas.a.roeseler@gmail.com> wrote:
> >
> > Modify the icmp_rcv function to check PROBE messages and call
> > icmp_echo
> > if a PROBE request is detected.
> >
> > Modify the existing icmp_echo function to respond ot both ping and
> > PROBE
> > requests.
> >
> > This was tested using a custom modification to the iputils package
> > and
> > wireshark. It supports IPV4 probing by name, ifindex, and probing
> > by
> > both IPV4 and IPV6 addresses. It currently does not support
> > responding
> > to probes off the proxy node (see RFC 8335 Section 2).
>
> If you happen to use github or something similar, if you don't mind
> sharing the code, you could clone the iputils repo and publish the
> changes. No pressure.
Should I include the link to the github repo in the patch?
>
> > net/ipv4/icmp.c | 145 +++++++++++++++++++++++++++++++++++++++++++-
> > ----
> > 1 file changed, 130 insertions(+), 15 deletions(-)
> >
> > diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
> > index 616e2dc1c8fa..f1530011b7bc 100644
> > --- a/net/ipv4/icmp.c
> > +++ b/net/ipv4/icmp.c
> > @@ -93,6 +93,10 @@
> > #include <net/ip_fib.h>
> > #include <net/l3mdev.h>
> >
> > +#if IS_ENABLED(CONFIG_IPV6)
> > +#include <net/addrconf.h>
> > +#endif
>
> I don't think the conditional is needed (?)
>
> > static bool icmp_echo(struct sk_buff *skb)
> > {
> > + struct icmp_ext_hdr *ext_hdr, _ext_hdr;
> > + struct icmp_ext_echo_iio *iio, _iio;
> > + struct icmp_bxm icmp_param;
> > + struct net_device *dev;
> > struct net *net;
> > + u16 ident_len;
> > + char *buff;
> > + u8 status;
> >
> > net = dev_net(skb_dst(skb)->dev);
> > - if (!net->ipv4.sysctl_icmp_echo_ignore_all) {
> > - struct icmp_bxm icmp_param;
> > -
> > - icmp_param.data.icmph = *icmp_hdr(skb);
> > - icmp_param.data.icmph.type = ICMP_ECHOREPLY;
> > - icmp_param.skb = skb;
> > - icmp_param.offset = 0;
> > - icmp_param.data_len = skb->len;
> > - icmp_param.head_len = sizeof(struct
> > icmphdr);
> > - icmp_reply(&icmp_param, skb);
> > - }
> > /* should there be an ICMP stat for ignored echos? */
> > - return true;
> > + if (net->ipv4.sysctl_icmp_echo_ignore_all)
> > + return true;
> > +
> > + icmp_param.data.icmph = *icmp_hdr(skb);
> > + icmp_param.skb = skb;
> > + icmp_param.offset = 0;
> > + icmp_param.data_len = skb->len;
> > + icmp_param.head_len = sizeof(struct icmphdr);
> > +
> > + if (icmp_param.data.icmph.type == ICMP_ECHO)
> > + goto send_reply;
>
> Is this path now missing
>
> icmp_param.data.icmph.type = ICMP_ECHOREPLY;
>
> > + if (!net->ipv4.sysctl_icmp_echo_enable_probe)
> > + return true;
> > + /* We currently only support probing interfaces on the
> > proxy node
> > + * Check to ensure L-bit is set
> > + */
> > + if (!(ntohs(icmp_param.data.icmph.un.echo.sequence) & 1))
> > + return true;
> > + /* Clear status bits in reply message */
> > + icmp_param.data.icmph.un.echo.sequence &= htons(0xFF00);
> > + icmp_param.data.icmph.type = ICMP_EXT_ECHOREPLY;
> > + ext_hdr = skb_header_pointer(skb, 0, sizeof(_ext_hdr),
> > &_ext_hdr);
> > + iio = skb_header_pointer(skb, sizeof(_ext_hdr),
> > sizeof(_iio), &_iio);
> > + if (!ext_hdr || !iio)
> > + goto send_mal_query;
> > + if (ntohs(iio->extobj_hdr.length) <= sizeof(iio-
> > >extobj_hdr))
> > + goto send_mal_query;
> > + ident_len = ntohs(iio->extobj_hdr.length) - sizeof(iio-
> > >extobj_hdr);
> > + status = 0;
> > + dev = NULL;
> > + switch (iio->extobj_hdr.class_type) {
> > + case EXT_ECHO_CTYPE_NAME:
> > + if (ident_len >= IFNAMSIZ)
> > + goto send_mal_query;
> > + buff = kcalloc(IFNAMSIZ, sizeof(char), GFP_KERNEL);
> > + if (!buff)
> > + return -ENOMEM;
> > + memcpy(buff, &iio->ident.name, ident_len);
> > + /* RFC 8335 2.1 If the Object Payload would not
> > otherwise terminate
> > + * on a 32-bit boundary, it MUST be padded with
> > ASCII NULL characters
> > + */
> > + if (ident_len % sizeof(u32) != 0) {
> > + u8 i;
> > +
> > + for (i = ident_len; i % sizeof(u32) != 0;
> > i++) {
> > + if (buff[i] != '\0')
> > + goto send_mal_query;
>
> Memory leak. IFNAMSIZ is small enough that you can use on-stack
> allocation
>
> Also, I think you can ignore if there are non-zero bytes beyond the
> len. We need to safely parse to avoid integrity bugs in the kernel.
> Beyond that, it's fine to be strict about what you send, liberal what
> you accept.
This checks that the incoming request is padded to the nearest 32-bit
boundary by ASCII NULL characters, as specified by RFC 8335
>
> > + }
> > + }
> > + dev = dev_get_by_name(net, buff);
> > + kfree(buff);
> > + break;
> > + case EXT_ECHO_CTYPE_INDEX:
> > + if (ident_len != sizeof(iio->ident.ifindex))
> > + goto send_mal_query;
> > + dev = dev_get_by_index(net, ntohl(iio-
> > >ident.ifindex));
> > + break;
> > + case EXT_ECHO_CTYPE_ADDR:
> > + if (ident_len != sizeof(iio->ident.addr.ctype3_hdr)
> > + iio->ident.addr.ctype3_hdr.addrlen)
> > + goto send_mal_query;
> > + switch (ntohs(iio->ident.addr.ctype3_hdr.afi)) {
> > + case ICMP_AFI_IP:
> > + if (ident_len != sizeof(iio-
> > >ident.addr.ctype3_hdr) + sizeof(struct in_addr))
> > + goto send_mal_query;
> > + dev = ip_dev_find(net, iio-
> > >ident.addr.ip_addr.ipv4_addr.s_addr);
> > + break;
> > +#if IS_ENABLED(CONFIG_IPV6)
> > + case ICMP_AFI_IP6:
> > + if (ident_len != sizeof(iio-
> > >ident.addr.ctype3_hdr) + sizeof(struct in6_addr))
> > + goto send_mal_query;
> > + rcu_read_lock();
> > + dev = ipv6_dev_find(net, &iio-
> > >ident.addr.ip_addr.ipv6_addr, dev);
> > + if (dev)
> > + dev_hold(dev);
> > + rcu_read_unlock();
> > + break;
> > +#endif
> > + default:
> > + goto send_mal_query;
> > + }
> > + break;
> > + default:
> > + goto send_mal_query;
> > + }
> > + if (!dev) {
> > + icmp_param.data.icmph.code = ICMP_EXT_NO_IF;
> > + goto send_reply;
> > + }
> > + /* Fill bits in reply message */
> > + if (dev->flags & IFF_UP)
> > + status |= EXT_ECHOREPLY_ACTIVE;
> > + if (__in_dev_get_rcu(dev) && __in_dev_get_rcu(dev)-
> > >ifa_list)
> > + status |= EXT_ECHOREPLY_IPV4;
> > + if (!list_empty(&dev->ip6_ptr->addr_list))
> > + status |= EXT_ECHOREPLY_IPV6;
> > + dev_put(dev);
> > + icmp_param.data.icmph.un.echo.sequence |= htons(status);
> > +send_reply:
> > + icmp_reply(&icmp_param, skb);
> > + return true;
> > +send_mal_query:
> > + icmp_param.data.icmph.code = ICMP_EXT_MAL_QUERY;
> > + goto send_reply;
> > }
> >
> > /*
> > @@ -1088,6 +1192,11 @@ int icmp_rcv(struct sk_buff *skb)
> > icmph = icmp_hdr(skb);
> >
> > ICMPMSGIN_INC_STATS(net, icmph->type);
> > +
> > + /* Check for ICMP Extended Echo (PROBE) messages */
> > + if (icmph->type == ICMP_EXT_ECHO)
> > + goto probe;
> > +
> > /*
> > * 18 is the highest 'known' ICMP type. Anything else
> > is a mystery
> > *
> > @@ -1097,7 +1206,6 @@ int icmp_rcv(struct sk_buff *skb)
> > if (icmph->type > NR_ICMP_TYPES)
> > goto error;
> >
> > -
> > /*
> > * Parse the ICMP message
> > */
> > @@ -1123,7 +1231,7 @@ int icmp_rcv(struct sk_buff *skb)
> > }
> >
> > success = icmp_pointers[icmph->type].handler(skb);
> > -
> > +success_check:
> > if (success) {
> > consume_skb(skb);
> > return NET_RX_SUCCESS;
> > @@ -1137,6 +1245,12 @@ int icmp_rcv(struct sk_buff *skb)
> > error:
> > __ICMP_INC_STATS(net, ICMP_MIB_INERRORS);
> > goto drop;
> > +probe:
> > + /* We can't use icmp_pointers[].handler() because it is an
> > array of
> > + * size NR_ICMP_TYPES + 1 (19 elements) and PROBE has code
> > 42.
> > + */
> > + success = icmp_echo(skb);
> > + goto success_check;
>
> just make this a branch instead of
Could you clarify this comment? Do you mean move this code to the
section where we check for PROBE messages instead of jumping to probe
and then jumping to success_check?
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH V4 net-next 5/5] icmp: add response to RFC 8335 PROBE messages
2021-03-15 19:09 ` Andreas Roeseler
@ 2021-03-15 19:34 ` Willem de Bruijn
0 siblings, 0 replies; 18+ messages in thread
From: Willem de Bruijn @ 2021-03-15 19:34 UTC (permalink / raw)
To: Andreas Roeseler
Cc: Willem de Bruijn, David Miller, Hideaki YOSHIFUJI, David Ahern,
Jakub Kicinski, Network Development
On Mon, Mar 15, 2021 at 3:10 PM Andreas Roeseler
<andreas.a.roeseler@gmail.com> wrote:
>
> On Mon, 2021-03-15 at 11:50 -0400, Willem de Bruijn wrote:
> > On Sun, Mar 14, 2021 at 12:50 PM Andreas Roeseler
> > <andreas.a.roeseler@gmail.com> wrote:
> > >
> > > Modify the icmp_rcv function to check PROBE messages and call
> > > icmp_echo
> > > if a PROBE request is detected.
> > >
> > > Modify the existing icmp_echo function to respond ot both ping and
> > > PROBE
> > > requests.
> > >
> > > This was tested using a custom modification to the iputils package
> > > and
> > > wireshark. It supports IPV4 probing by name, ifindex, and probing
> > > by
> > > both IPV4 and IPV6 addresses. It currently does not support
> > > responding
> > > to probes off the proxy node (see RFC 8335 Section 2).
> >
> > If you happen to use github or something similar, if you don't mind
> > sharing the code, you could clone the iputils repo and publish the
> > changes. No pressure.
>
> Should I include the link to the github repo in the patch?
If you don't mind, please do. It can serve as example for others to
use the feature, too.
>
> >
> > > net/ipv4/icmp.c | 145 +++++++++++++++++++++++++++++++++++++++++++-
> > > ----
> > > 1 file changed, 130 insertions(+), 15 deletions(-)
> > >
> > > diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
> > > index 616e2dc1c8fa..f1530011b7bc 100644
> > > --- a/net/ipv4/icmp.c
> > > +++ b/net/ipv4/icmp.c
> > > @@ -93,6 +93,10 @@
> > > #include <net/ip_fib.h>
> > > #include <net/l3mdev.h>
> > >
> > > +#if IS_ENABLED(CONFIG_IPV6)
> > > +#include <net/addrconf.h>
> > > +#endif
> >
> > I don't think the conditional is needed (?)
> >
> > > static bool icmp_echo(struct sk_buff *skb)
> > > {
> > > + struct icmp_ext_hdr *ext_hdr, _ext_hdr;
> > > + struct icmp_ext_echo_iio *iio, _iio;
> > > + struct icmp_bxm icmp_param;
> > > + struct net_device *dev;
> > > struct net *net;
> > > + u16 ident_len;
> > > + char *buff;
> > > + u8 status;
> > >
> > > net = dev_net(skb_dst(skb)->dev);
> > > - if (!net->ipv4.sysctl_icmp_echo_ignore_all) {
> > > - struct icmp_bxm icmp_param;
> > > -
> > > - icmp_param.data.icmph = *icmp_hdr(skb);
> > > - icmp_param.data.icmph.type = ICMP_ECHOREPLY;
> > > - icmp_param.skb = skb;
> > > - icmp_param.offset = 0;
> > > - icmp_param.data_len = skb->len;
> > > - icmp_param.head_len = sizeof(struct
> > > icmphdr);
> > > - icmp_reply(&icmp_param, skb);
> > > - }
> > > /* should there be an ICMP stat for ignored echos? */
> > > - return true;
> > > + if (net->ipv4.sysctl_icmp_echo_ignore_all)
> > > + return true;
> > > +
> > > + icmp_param.data.icmph = *icmp_hdr(skb);
> > > + icmp_param.skb = skb;
> > > + icmp_param.offset = 0;
> > > + icmp_param.data_len = skb->len;
> > > + icmp_param.head_len = sizeof(struct icmphdr);
> > > +
> > > + if (icmp_param.data.icmph.type == ICMP_ECHO)
> > > + goto send_reply;
> >
> > Is this path now missing
> >
> > icmp_param.data.icmph.type = ICMP_ECHOREPLY;
> >
> > > + if (!net->ipv4.sysctl_icmp_echo_enable_probe)
> > > + return true;
> > > + /* We currently only support probing interfaces on the
> > > proxy node
> > > + * Check to ensure L-bit is set
> > > + */
> > > + if (!(ntohs(icmp_param.data.icmph.un.echo.sequence) & 1))
> > > + return true;
> > > + /* Clear status bits in reply message */
> > > + icmp_param.data.icmph.un.echo.sequence &= htons(0xFF00);
> > > + icmp_param.data.icmph.type = ICMP_EXT_ECHOREPLY;
> > > + ext_hdr = skb_header_pointer(skb, 0, sizeof(_ext_hdr),
> > > &_ext_hdr);
> > > + iio = skb_header_pointer(skb, sizeof(_ext_hdr),
> > > sizeof(_iio), &_iio);
> > > + if (!ext_hdr || !iio)
> > > + goto send_mal_query;
> > > + if (ntohs(iio->extobj_hdr.length) <= sizeof(iio-
> > > >extobj_hdr))
> > > + goto send_mal_query;
> > > + ident_len = ntohs(iio->extobj_hdr.length) - sizeof(iio-
> > > >extobj_hdr);
> > > + status = 0;
> > > + dev = NULL;
> > > + switch (iio->extobj_hdr.class_type) {
> > > + case EXT_ECHO_CTYPE_NAME:
> > > + if (ident_len >= IFNAMSIZ)
> > > + goto send_mal_query;
> > > + buff = kcalloc(IFNAMSIZ, sizeof(char), GFP_KERNEL);
> > > + if (!buff)
> > > + return -ENOMEM;
> > > + memcpy(buff, &iio->ident.name, ident_len);
> > > + /* RFC 8335 2.1 If the Object Payload would not
> > > otherwise terminate
> > > + * on a 32-bit boundary, it MUST be padded with
> > > ASCII NULL characters
> > > + */
> > > + if (ident_len % sizeof(u32) != 0) {
> > > + u8 i;
> > > +
> > > + for (i = ident_len; i % sizeof(u32) != 0;
> > > i++) {
> > > + if (buff[i] != '\0')
> > > + goto send_mal_query;
> >
> > Memory leak. IFNAMSIZ is small enough that you can use on-stack
> > allocation
> >
> > Also, I think you can ignore if there are non-zero bytes beyond the
> > len. We need to safely parse to avoid integrity bugs in the kernel.
> > Beyond that, it's fine to be strict about what you send, liberal what
> > you accept.
>
> This checks that the incoming request is padded to the nearest 32-bit
> boundary by ASCII NULL characters, as specified by RFC 8335
Right. The question is whether you need to be strict in enforcing
that. Perhaps the RFC states that explicitly. Else, it's up to your
interpretation. I suggested the robustness principle, which is
commonly employed in such instances.
> >
> > > + }
> > > + }
> > > + dev = dev_get_by_name(net, buff);
> > > + kfree(buff);
> > > + break;
> > > + case EXT_ECHO_CTYPE_INDEX:
> > > + if (ident_len != sizeof(iio->ident.ifindex))
> > > + goto send_mal_query;
> > > + dev = dev_get_by_index(net, ntohl(iio-
> > > >ident.ifindex));
> > > + break;
> > > + case EXT_ECHO_CTYPE_ADDR:
> > > + if (ident_len != sizeof(iio->ident.addr.ctype3_hdr)
> > > + iio->ident.addr.ctype3_hdr.addrlen)
> > > + goto send_mal_query;
> > > + switch (ntohs(iio->ident.addr.ctype3_hdr.afi)) {
> > > + case ICMP_AFI_IP:
> > > + if (ident_len != sizeof(iio-
> > > >ident.addr.ctype3_hdr) + sizeof(struct in_addr))
> > > + goto send_mal_query;
> > > + dev = ip_dev_find(net, iio-
> > > >ident.addr.ip_addr.ipv4_addr.s_addr);
> > > + break;
> > > +#if IS_ENABLED(CONFIG_IPV6)
> > > + case ICMP_AFI_IP6:
> > > + if (ident_len != sizeof(iio-
> > > >ident.addr.ctype3_hdr) + sizeof(struct in6_addr))
> > > + goto send_mal_query;
> > > + rcu_read_lock();
> > > + dev = ipv6_dev_find(net, &iio-
> > > >ident.addr.ip_addr.ipv6_addr, dev);
> > > + if (dev)
> > > + dev_hold(dev);
> > > + rcu_read_unlock();
> > > + break;
> > > +#endif
> > > + default:
> > > + goto send_mal_query;
> > > + }
> > > + break;
> > > + default:
> > > + goto send_mal_query;
> > > + }
> > > + if (!dev) {
> > > + icmp_param.data.icmph.code = ICMP_EXT_NO_IF;
> > > + goto send_reply;
> > > + }
> > > + /* Fill bits in reply message */
> > > + if (dev->flags & IFF_UP)
> > > + status |= EXT_ECHOREPLY_ACTIVE;
> > > + if (__in_dev_get_rcu(dev) && __in_dev_get_rcu(dev)-
> > > >ifa_list)
> > > + status |= EXT_ECHOREPLY_IPV4;
> > > + if (!list_empty(&dev->ip6_ptr->addr_list))
> > > + status |= EXT_ECHOREPLY_IPV6;
> > > + dev_put(dev);
> > > + icmp_param.data.icmph.un.echo.sequence |= htons(status);
> > > +send_reply:
> > > + icmp_reply(&icmp_param, skb);
> > > + return true;
> > > +send_mal_query:
> > > + icmp_param.data.icmph.code = ICMP_EXT_MAL_QUERY;
> > > + goto send_reply;
> > > }
> > >
> > > /*
> > > @@ -1088,6 +1192,11 @@ int icmp_rcv(struct sk_buff *skb)
> > > icmph = icmp_hdr(skb);
> > >
> > > ICMPMSGIN_INC_STATS(net, icmph->type);
> > > +
> > > + /* Check for ICMP Extended Echo (PROBE) messages */
> > > + if (icmph->type == ICMP_EXT_ECHO)
> > > + goto probe;
> > > +
> > > /*
> > > * 18 is the highest 'known' ICMP type. Anything else
> > > is a mystery
> > > *
> > > @@ -1097,7 +1206,6 @@ int icmp_rcv(struct sk_buff *skb)
> > > if (icmph->type > NR_ICMP_TYPES)
> > > goto error;
> > >
> > > -
> > > /*
> > > * Parse the ICMP message
> > > */
> > > @@ -1123,7 +1231,7 @@ int icmp_rcv(struct sk_buff *skb)
> > > }
> > >
> > > success = icmp_pointers[icmph->type].handler(skb);
> > > -
> > > +success_check:
> > > if (success) {
> > > consume_skb(skb);
> > > return NET_RX_SUCCESS;
> > > @@ -1137,6 +1245,12 @@ int icmp_rcv(struct sk_buff *skb)
> > > error:
> > > __ICMP_INC_STATS(net, ICMP_MIB_INERRORS);
> > > goto drop;
> > > +probe:
> > > + /* We can't use icmp_pointers[].handler() because it is an
> > > array of
> > > + * size NR_ICMP_TYPES + 1 (19 elements) and PROBE has code
> > > 42.
> > > + */
> > > + success = icmp_echo(skb);
> > > + goto success_check;
> >
> > just make this a branch instead of
>
> Could you clarify this comment? Do you mean move this code to the
> section where we check for PROBE messages instead of jumping to probe
> and then jumping to success_check?
Exactly
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH V4 net-next 5/5] icmp: add response to RFC 8335 PROBE messages
2021-03-14 20:35 ` kernel test robot
@ 2021-03-18 3:11 ` Andreas Roeseler
2021-03-18 3:19 ` David Miller
0 siblings, 1 reply; 18+ messages in thread
From: Andreas Roeseler @ 2021-03-18 3:11 UTC (permalink / raw)
To: Network Development
Cc: David Miller, Hideaki YOSHIFUJI, Jakub Kicinski, David Ahern
On Mon, 2021-03-15 at 04:35 +0800, kernel test robot wrote:
> Hi Andreas,
>
> [FYI, it's a private test report for your RFC patch.]
> [auto build test ERROR on net-next/master]
>
> url:
> https://github.com/0day-ci/linux/commits/Andreas-Roeseler/add-support-for-RFC-8335-PROBE/20210315-005052
> base:
> https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 6f
> 1629093399303bf19d6fcd5144061d1e25ec23
> config: mips-allmodconfig (attached as .config)
> compiler: mips-linux-gcc (GCC) 9.3.0
> reproduce (this is a W=1 build):
> wget
> https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross
> -O ~/bin/make.cross
> chmod +x ~/bin/make.cross
> #
> https://github.com/0day-ci/linux/commit/54d9928f1734e7b3511b945a2ce912b931a07776
> git remote add linux-review https://github.com/0day-ci/linux
> git fetch --no-tags linux-review Andreas-Roeseler/add-
> support-for-RFC-8335-PROBE/20210315-005052
> git checkout 54d9928f1734e7b3511b945a2ce912b931a07776
> # save the attached .config to linux build tree
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0
> make.cross ARCH=mips
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
>
> All errors (new ones prefixed by >>):
>
> mips-linux-ld: net/ipv4/icmp.o: in function `icmp_echo':
> > > icmp.c:(.text.icmp_echo+0x658): undefined reference to
> > > `ipv6_dev_find'
>
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
I'm still learning the ropes of kernel development and I was wondering
if someone could help me figure out what is causing this error.
The file compiles when compiling with allyesconfig or olddefconfig, but
it cannot find the ipv6_dev_find() function when compiling with
allmodconfig and returns the error seen above. I am including
<include/net/addrconf.h> which declares ipv6_dev_find(), and the
function is defined and exported using EXPORT_SYMBOL in
<net/ipv6/addrconf.c>. I've tried declaring the function via extern in
<include/net/icmp.h> and in <net/ipv4/icmp.c>, but neither have
resolved the error and checkpatch.pl explicitly warns against using
extern calls in .c files.
Is there something that I'm not understanding about compiling kernel
components modularly? How do I avoid this error?
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH V4 net-next 5/5] icmp: add response to RFC 8335 PROBE messages
2021-03-18 3:11 ` Andreas Roeseler
@ 2021-03-18 3:19 ` David Miller
2021-03-18 3:24 ` David Ahern
0 siblings, 1 reply; 18+ messages in thread
From: David Miller @ 2021-03-18 3:19 UTC (permalink / raw)
To: andreas.a.roeseler; +Cc: netdev, yoshfuji, kuba, dsahern
From: Andreas Roeseler <andreas.a.roeseler@gmail.com>
Date: Wed, 17 Mar 2021 22:11:47 -0500
> On Mon, 2021-03-15 at 04:35 +0800, kernel test robot wrote:
> Is there something that I'm not understanding about compiling kernel
> components modularly? How do I avoid this error?
>
You cannot reference module exported symbols from statically linked code.
y
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH V4 net-next 5/5] icmp: add response to RFC 8335 PROBE messages
2021-03-18 3:19 ` David Miller
@ 2021-03-18 3:24 ` David Ahern
2021-03-20 16:01 ` Andreas Roeseler
0 siblings, 1 reply; 18+ messages in thread
From: David Ahern @ 2021-03-18 3:24 UTC (permalink / raw)
To: David Miller, andreas.a.roeseler; +Cc: netdev, yoshfuji, kuba, dsahern
On 3/17/21 9:19 PM, David Miller wrote:
> From: Andreas Roeseler <andreas.a.roeseler@gmail.com>
> Date: Wed, 17 Mar 2021 22:11:47 -0500
>
>> On Mon, 2021-03-15 at 04:35 +0800, kernel test robot wrote:
>> Is there something that I'm not understanding about compiling kernel
>> components modularly? How do I avoid this error?
>
>>
> You cannot reference module exported symbols from statically linked code.
> y
>
Look at ipv6_stub to see how it exports IPv6 functions for v4 code.
There are a few examples under net/ipv4.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH V4 net-next 5/5] icmp: add response to RFC 8335 PROBE messages
2021-03-18 3:24 ` David Ahern
@ 2021-03-20 16:01 ` Andreas Roeseler
2021-03-20 16:43 ` David Ahern
0 siblings, 1 reply; 18+ messages in thread
From: Andreas Roeseler @ 2021-03-20 16:01 UTC (permalink / raw)
To: David Ahern, David Miller; +Cc: netdev, yoshfuji, kuba, dsahern
On Wed, 2021-03-17 at 21:24 -0600, David Ahern wrote:
> On 3/17/21 9:19 PM, David Miller wrote:
> > From: Andreas Roeseler <andreas.a.roeseler@gmail.com>
> > Date: Wed, 17 Mar 2021 22:11:47 -0500
> >
> > > On Mon, 2021-03-15 at 04:35 +0800, kernel test robot wrote:
> > > Is there something that I'm not understanding about compiling
> > > kernel
> > > components modularly? How do I avoid this error?
> >
> > >
> > You cannot reference module exported symbols from statically linked
> > code.
> > y
> >
>
> Look at ipv6_stub to see how it exports IPv6 functions for v4 code.
> There are a few examples under net/ipv4.
Thanks for the advice. I've been able to make some progress but I still
have some questions that I have been unable to find online.
What steps are required to include a function into the ipv6_stub
struct? I've added the declaration of the function to the struct, but
when I attempt to call it using <ipv6_stub->ipv6_dev_find()> the kernel
locks up. Additionally, a typo in the declaration isn't flagged during
compilation. Are there other places where I need to edit the ipv6_stub
struct or include various headers? The examples I have looked at are
<fib_semantics.c>, <nexthop.c>, and <udp.c> in the <net/ipv4> folder
and they don't seem to do anything on the caller side of ipv6_stub, so
I think I am not adding the function to ipv6_stub properly. I have been
able to call other functions that currently exist in ipv6_stub, but not
the one I am attempting to add, so am I missing a step?
I've noticed that some functions such as <ipv6_route_input> aren't
exported using EXPORT_SYMBOL when it is defined in
<net/ipv6/af_inet6.c>, but it is still loaded into ipv6_stub. How can
this be? Is there a different way to include symbols into ipv6_stub
based on whether or not they are explicitly exported using
EXPORT_SYMBOL?
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH V4 net-next 5/5] icmp: add response to RFC 8335 PROBE messages
2021-03-20 16:01 ` Andreas Roeseler
@ 2021-03-20 16:43 ` David Ahern
0 siblings, 0 replies; 18+ messages in thread
From: David Ahern @ 2021-03-20 16:43 UTC (permalink / raw)
To: Andreas Roeseler, David Miller; +Cc: netdev, yoshfuji, kuba, dsahern
On 3/20/21 10:01 AM, Andreas Roeseler wrote:
> On Wed, 2021-03-17 at 21:24 -0600, David Ahern wrote:
>> On 3/17/21 9:19 PM, David Miller wrote:
>>> From: Andreas Roeseler <andreas.a.roeseler@gmail.com>
>>> Date: Wed, 17 Mar 2021 22:11:47 -0500
>>>
>>>> On Mon, 2021-03-15 at 04:35 +0800, kernel test robot wrote:
>>>> Is there something that I'm not understanding about compiling
>>>> kernel
>>>> components modularly? How do I avoid this error?
>>>
>>>>
>>> You cannot reference module exported symbols from statically linked
>>> code.
>>> y
>>>
>>
>> Look at ipv6_stub to see how it exports IPv6 functions for v4 code.
>> There are a few examples under net/ipv4.
>
> Thanks for the advice. I've been able to make some progress but I still
> have some questions that I have been unable to find online.
>
> What steps are required to include a function into the ipv6_stub
> struct? I've added the declaration of the function to the struct, but
> when I attempt to call it using <ipv6_stub->ipv6_dev_find()> the kernel
> locks up. Additionally, a typo in the declaration isn't flagged during
> compilation. Are there other places where I need to edit the ipv6_stub
> struct or include various headers? The examples I have looked at are
> <fib_semantics.c>, <nexthop.c>, and <udp.c> in the <net/ipv4> folder
> and they don't seem to do anything on the caller side of ipv6_stub, so
> I think I am not adding the function to ipv6_stub properly. I have been
> able to call other functions that currently exist in ipv6_stub, but not
> the one I am attempting to add, so am I missing a step?
you probably did not add the default in net/ipv6/addrconf_core.c.
>
> I've noticed that some functions such as <ipv6_route_input> aren't
> exported using EXPORT_SYMBOL when it is defined in
> <net/ipv6/af_inet6.c>, but it is still loaded into ipv6_stub. How can
> this be? Is there a different way to include symbols into ipv6_stub
> based on whether or not they are explicitly exported using
> EXPORT_SYMBOL?
>
take a look at 1aefd3de7bc6 as an example of how to add a new stub.
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2021-03-20 16:43 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-14 16:48 [PATCH V4 net-next 0/5] add support for RFC 8335 PROBE Andreas Roeseler
2021-03-14 16:48 ` [PATCH V4 net-next 1/5] icmp: " Andreas Roeseler
2021-03-14 16:48 ` [PATCH V4 net-next 2/5] ICMPV6: " Andreas Roeseler
2021-03-14 16:48 ` [PATCH V4 net-next 3/5] net: add sysctl for enabling RFC 8335 PROBE messages Andreas Roeseler
2021-03-14 16:48 ` [PATCH V4 net-next 4/5] net: add support for sending " Andreas Roeseler
2021-03-14 16:48 ` [PATCH V4 net-next 5/5] icmp: add response to " Andreas Roeseler
2021-03-14 17:59 ` kernel test robot
2021-03-14 18:32 ` kernel test robot
2021-03-14 18:33 ` kernel test robot
2021-03-14 20:35 ` kernel test robot
2021-03-18 3:11 ` Andreas Roeseler
2021-03-18 3:19 ` David Miller
2021-03-18 3:24 ` David Ahern
2021-03-20 16:01 ` Andreas Roeseler
2021-03-20 16:43 ` David Ahern
2021-03-15 15:50 ` Willem de Bruijn
2021-03-15 19:09 ` Andreas Roeseler
2021-03-15 19:34 ` Willem de Bruijn
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.