<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>net_arp: Memory fault in in arp_entry_cleanup</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/105286/net_arp-memory-fault-in-in-arp_entry_cleanup</link><description>I have run into an issue when trying to send a UDP packet using the nRF7002 DK evaluation board. I observed it with NCS v2.2.0, but just also pulled up to v2.5.0 and have the same problem. 
 In arp_entry_cleanup(), there are 2 packets in the ARP entry</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 30 Nov 2023 12:27:04 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/105286/net_arp-memory-fault-in-in-arp_entry_cleanup" /><item><title>RE: net_arp: Memory fault in in arp_entry_cleanup</title><link>https://devzone.nordicsemi.com/thread/458285?ContentTypeID=1</link><pubDate>Thu, 30 Nov 2023 12:27:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f908b012-0b25-468c-913e-0519488e7e8d</guid><dc:creator>Elfving</dc:creator><description>&lt;p&gt;Hello again Daniel, and sorry about the delay here.&lt;/p&gt;
&lt;p&gt;I had a talk with a developer&amp;nbsp;working on this who agree that this doesn&amp;#39;t look right. &lt;a href="https://github.com/nrfconnect/sdk-zephyr/commit/55802e5e8637949b113a9f225c9f9a11f7f9b49d#diff-7f759f2a2f63c258dbebf2da89dde3c88a24746f1141b716a00dc19704cf02de"&gt;It seems that we do ARP cleanup in case of TX error&lt;/a&gt;,&amp;nbsp;&lt;span&gt;&lt;span dir="ltr"&gt;but not in other cases (like out-of-buf issue on header allocation). This would cause dereferencing the packet on the ARP queue. We&amp;#39;ll try to reproduce and provide a fix upstream.&lt;br /&gt;&lt;br /&gt;Quick update:&lt;br /&gt;&lt;a href="https://github.com/zephyrproject-rtos/zephyr/pull/65975"&gt;This PR &lt;/a&gt;should fix the&amp;nbsp;&lt;span dir="ltr"&gt;double packet dereference and ARP packet leak in case of out-of-mem issues. And another thing is that the minimum amount of net buffers configured for sending a UDP are 3. I&amp;#39;ve looked into why we don&amp;#39;t enforce a minimum of something like 3, but what the minimum is differs a lot depending&amp;nbsp;on your&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:12px;"&gt;configuration.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Elfving&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: net_arp: Memory fault in in arp_entry_cleanup</title><link>https://devzone.nordicsemi.com/thread/456545?ContentTypeID=1</link><pubDate>Mon, 20 Nov 2023 19:35:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e25d41d-327e-4566-9a0a-a89cf0dd0f9e</guid><dc:creator>Daniel K</dc:creator><description>&lt;p&gt;I had noticed that net_pkt_clone() was used in a couple of places, but possibly unchecked...&lt;br /&gt;In zephyr/subsys/net/ip/tp.c:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;struct net_pkt *tp_pkt_clone(struct net_pkt *pkt, const char *file, int line)
{
	struct tp_pkt *tp_pkt = k_malloc(sizeof(struct tp_pkt));

	pkt = net_pkt_clone(pkt, K_NO_WAIT);

	tp_pkt-&amp;gt;pkt = pkt;
	tp_pkt-&amp;gt;file = file;
	tp_pkt-&amp;gt;line = line;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In zephyr/subsys/net/ip/net_if.c:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;		verdict = net_if_l2(iface)-&amp;gt;recv(iface, pkt);
		if (verdict == NET_CONTINUE) {
			new_pkt = net_pkt_clone(pkt, K_NO_WAIT);
		} else {
			new_pkt = net_pkt_ref(pkt);
		}

		/* L2 has modified the buffer starting point, it is easier
		 * to re-initialize the cursor rather than updating it.
		 */
		net_pkt_cursor_init(new_pkt);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: net_arp: Memory fault in in arp_entry_cleanup</title><link>https://devzone.nordicsemi.com/thread/456526?ContentTypeID=1</link><pubDate>Mon, 20 Nov 2023 17:11:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:33e0d841-bbfc-4bba-9b3b-41550f3d6844</guid><dc:creator>Daniel K</dc:creator><description>&lt;p&gt;Hi sorry for the late reply.&amp;nbsp; Increasing it fixes the immediate problem, but my concern is that there is some case of unchecked allocation failure causing memory corruption.&amp;nbsp; In that case, no matter how large the buffer is, there is always a possibility of memory corruption and crash.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: net_arp: Memory fault in in arp_entry_cleanup</title><link>https://devzone.nordicsemi.com/thread/454655?ContentTypeID=1</link><pubDate>Wed, 08 Nov 2023 12:14:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f5f6be6e-5771-4b6d-bdd4-073abc0aac50</guid><dc:creator>Elfving</dc:creator><description>&lt;p&gt;Hello Daniel,&lt;/p&gt;
&lt;p&gt;Yeah, I guess it makes sense that some packets are released when the buffers are that low. I&amp;#39;ve seen some similar cases to this before.&lt;/p&gt;
&lt;p&gt;For TX, the buffers have to twice that of packets (Each Ethernet TX frame occupies two buffers). Ie.&amp;nbsp;for your case:&lt;/p&gt;
&lt;p&gt;CONFIG_NET_BUF_RX_COUNT=6&lt;br /&gt;CONFIG_NET_BUF_TX_COUNT=12&lt;/p&gt;
&lt;p&gt;But try to increase the buffers even more, eg. 50 and 100. For performance testing you could for instance have a look at&amp;nbsp;&lt;code&gt;overlay-zperf.conf&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;that has optimized settings for this.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am not exactly seeing why a buffer that low should make it crash, though the default seems to be 16. So 6 is a bit low. Does increasing it fix all the issues for you?&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Elfving&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: net_arp: Memory fault in in arp_entry_cleanup</title><link>https://devzone.nordicsemi.com/thread/453836?ContentTypeID=1</link><pubDate>Thu, 02 Nov 2023 18:38:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b777ed6c-a156-4b48-aa5b-3c412302eac8</guid><dc:creator>Daniel K</dc:creator><description>&lt;p&gt;I found that increasing CONFIG_NET_BUF_TX_COUNT from 2 to 8 fixes the issue, although it&amp;#39;s concerning it doesn&amp;#39;t have any enforced minimum.&lt;/p&gt;
&lt;p&gt;I suppose somewhere a packet is being allocated unsuccessfully and not being checked.&amp;nbsp; It doesn&amp;#39;t fix the actual root cause of the crash though.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: net_arp: Memory fault in in arp_entry_cleanup</title><link>https://devzone.nordicsemi.com/thread/453813?ContentTypeID=1</link><pubDate>Thu, 02 Nov 2023 15:58:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0716b085-6d3b-4a1a-af03-c7cd75e66669</guid><dc:creator>Daniel K</dc:creator><description>&lt;p&gt;I think there has to be a memory corruption issue.&amp;nbsp; For testing purposes, I changed the while loop in arp_entry_cleanup() to skip over entries that are probably corrupt just to see if it would still transmit:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;pre class="ui-code" data-mode="text"&gt;		while (!k_fifo_is_empty(&amp;amp;entry-&amp;gt;pending_queue)) {
			pkt = k_fifo_get(&amp;amp;entry-&amp;gt;pending_queue, K_FOREVER);
			atomic_val_t ref = atomic_get(&amp;amp;pkt-&amp;gt;atomic_ref);
			if (ref == 1) {
				NET_INFO(&amp;quot;Releasing pending pkt %p (ref %ld)&amp;quot;, pkt, ref - 1);
				net_pkt_unref(pkt);
			} else {
				NET_INFO(&amp;quot;Skip released pending pkt %p (ref %ld)&amp;quot;, pkt, ref - 1);
			}
		}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Seems like the packets are getting corrupt, as the ref counts make no sense:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;[00:00:13.444,824] &amp;lt;inf&amp;gt; app: Sending 1 B to 192.168.0.4:49229&lt;br /&gt;[00:00:15.445,190] &amp;lt;inf&amp;gt; net_arp: Skip released pending pkt 0x2003aaa4 (ref -1)&lt;br /&gt;[00:00:15.445,220] &amp;lt;inf&amp;gt; net_arp: Skip released pending pkt 0x2003aa64 (ref 1391567922)&lt;br /&gt;[00:00:15.445,251] &amp;lt;inf&amp;gt; net_arp: Skip released pending pkt 0x2003aa24 (ref -794600311)&lt;br /&gt;[00:00:15.445,251] &amp;lt;inf&amp;gt; net_arp: Skip released pending pkt 0x2003a9e4 (ref -1327495242)&lt;br /&gt;[00:00:15.445,281] &amp;lt;inf&amp;gt; net_arp: Skip released pending pkt 0x2003a9a4 (ref -1091356391)&lt;br /&gt;[00:00:15.445,281] &amp;lt;inf&amp;gt; net_arp: Skip released pending pkt 0x2003a964 (ref -2070176309)&lt;br /&gt;[00:00:15.445,312] &amp;lt;inf&amp;gt; net_arp: Skip released pending pkt 0x2003a924 (ref 885680368)&lt;br /&gt;[00:00:15.445,312] &amp;lt;inf&amp;gt; net_arp: Skip released pending pkt 0x2003a8e4 (ref 1893167851)&lt;br /&gt;[00:00:15.445,343] &amp;lt;inf&amp;gt; net_arp: Skip released pending pkt 0x2003a8a4 (ref -1807458317)&lt;br /&gt;[00:00:15.445,373] &amp;lt;inf&amp;gt; net_arp: Skip released pending pkt 0x2003a864 (ref -1093865732)&lt;br /&gt;[00:00:15.445,373] &amp;lt;inf&amp;gt; net_arp: Skip released pending pkt 0x2003a824 (ref -1744161751)&lt;br /&gt;[00:00:15.445,404] &amp;lt;inf&amp;gt; net_arp: Skip released pending pkt 0x2003a7e4 (ref -187367831)&lt;br /&gt;[00:00:15.445,404] &amp;lt;inf&amp;gt; net_arp: Skip released pending pkt 0x2003a7a4 (ref 175564112)&lt;/p&gt;
&lt;p&gt;I think this leads to a memory leak, because eventually it starts failing every time to send a packet.&lt;/p&gt;
&lt;p&gt;[00:04:43.773,345] &amp;lt;inf&amp;gt; app: Sending 1 B to 192.168.0.4:49229&lt;br /&gt;[00:04:43.873,718] &amp;lt;err&amp;gt; net_pkt: Data buffer (28) allocation failed.&lt;/p&gt;
&lt;p&gt;I would guess that this means the packets must have actually NOT been freed, and were ignored instead of being sent.&lt;/p&gt;
&lt;p&gt;A Wireshark capture of ethernet packets only shows an XID broadcast, and the DHCP exchange; no other packets being sent.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: net_arp: Memory fault in in arp_entry_cleanup</title><link>https://devzone.nordicsemi.com/thread/453748?ContentTypeID=1</link><pubDate>Thu, 02 Nov 2023 13:45:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d2a4580-4a1b-4816-af75-cff305b2f2a4</guid><dc:creator>Daniel K</dc:creator><description>&lt;p&gt;Oh, one other thing.&amp;nbsp; I had added a log entry in arp_prepare() where the packet is added to the pending_queue:&lt;/p&gt;
&lt;div style="background-color:#1f1f1f;color:#cccccc;font-family:Consolas, &amp;#39;Courier New&amp;#39;, monospace;font-size:14px;font-weight:normal;line-height:19px;white-space:pre;"&gt;
&lt;div&gt;&lt;span style="color:#cccccc;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="color:#569cd6;"&gt;NET_DBG&lt;/span&gt;&lt;span style="color:#cccccc;"&gt;(&lt;/span&gt;&lt;span style="color:#ce9178;"&gt;&amp;quot;New pkt &lt;/span&gt;&lt;span style="color:#9cdcfe;"&gt;%p&lt;/span&gt;&lt;span style="color:#ce9178;"&gt; dst &lt;/span&gt;&lt;span style="color:#9cdcfe;"&gt;%s&lt;/span&gt;&lt;span style="color:#ce9178;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#cccccc;"&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#cccccc;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="color:#9cdcfe;"&gt;pending&lt;/span&gt;&lt;span style="color:#cccccc;"&gt;, &lt;/span&gt;&lt;span style="color:#569cd6;"&gt;net_sprint_ipv4_addr&lt;/span&gt;&lt;span style="color:#cccccc;"&gt;(&lt;/span&gt;&lt;span style="color:#d4d4d4;"&gt;&amp;amp;&lt;/span&gt;&lt;span style="color:#9cdcfe;"&gt;entry&lt;/span&gt;&lt;span style="color:#cccccc;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#9cdcfe;"&gt;ip&lt;/span&gt;&lt;span style="color:#cccccc;"&gt;));&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: net_arp: Memory fault in in arp_entry_cleanup</title><link>https://devzone.nordicsemi.com/thread/453722?ContentTypeID=1</link><pubDate>Thu, 02 Nov 2023 12:54:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ce36cf8d-4187-48e0-850b-99cabdf62b55</guid><dc:creator>Elfving</dc:creator><description>&lt;p&gt;Hello Daniel,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Just letting you know that I am looking into it.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Elfving&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>