<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Andrew Kanner on Medium]]></title>
        <description><![CDATA[Stories by Andrew Kanner on Medium]]></description>
        <link>https://medium.com/@andrew.kanner?source=rss-4a32ed55b262------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*02zkb8VhTIG3L5_0</url>
            <title>Stories by Andrew Kanner on Medium</title>
            <link>https://medium.com/@andrew.kanner?source=rss-4a32ed55b262------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 02:14:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@andrew.kanner/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Linux kernel Bug Fixing 2023 experience]]></title>
            <link>https://medium.com/@andrew.kanner/linux-kernel-bug-fixing-2023-experience-ce37aee844ee?source=rss-4a32ed55b262------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce37aee844ee</guid>
            <category><![CDATA[bugs]]></category>
            <category><![CDATA[mentorship]]></category>
            <category><![CDATA[bug-fixes]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[kernel]]></category>
            <dc:creator><![CDATA[Andrew Kanner]]></dc:creator>
            <pubDate>Fri, 17 Nov 2023 15:54:52 GMT</pubDate>
            <atom:updated>2023-11-17T16:12:55.035Z</atom:updated>
            <content:encoded><![CDATA[<p>In 2023 I participated in the <a href="https://mentorship.lfx.linuxfoundation.org/project/f1b93bd9-d58f-42e1-a088-752633a088ff">Linux kernel Mentorship program</a> and have some experience to share.</p><p>It was an interesting event in my dev career, just like <a href="http://eudyptula-challenge.org/">eudyptula challenge</a>, but with the real kernel devs instead of some automated scripts -)</p><p>First of all, let me note some requirements for the mentees:</p><ul><li>I recommend having some kernel dev experience before submission, it’s not mandatory, but believe me — it will be much easier for you to focus on the bugs instead of learning the process of submitting patches, or how the Linux kernel actually works.</li><li>You should prepare your CV and fill out the form about who you are and why you should be chosen for this mentorship program.</li><li>You should choose your preferred participation type — Full-time or Part-time. Full-time participation means that you should really focus on the mentorship. There are no strict rules, nobody counts your work time. But otherwise you might not meet the graduation requirement: 5–10 patches merged in the mainline.</li><li><a href="https://training.linuxfoundation.org/training/a-beginners-guide-to-linux-kernel-development-lfd103/">LFD-103</a> is really helpful, it has answers to the most common questions during the mentorship — you should take your time and finish it, reading and checking all the details.</li><li>There are several more tasks before you will be accepted, like: compile and boot the latest Linux kernel, write a Hello-world kernel module, investigate what is a stack trace and how to decode it, try to run some kselftests, etc. They are not really hard, but it’s a good time to think about how you will be re-compiling and re-running the kernel, you might need to do it really often.</li></ul><p>You should complete the assignments upon some deadline and if everything is alright — will be chosen and might participate as a mentee, which means more tasks to do in your dashboard.</p><p>This time the tasks will be mostly about debugging, tracing and some bug fixing internals.</p><p>The first thing I did was <em>nokaslr</em> kernel boot option. It’s a great feature, but sometimes it makes debugging harder.</p><p>Some tasks ask you to watch a webinar and write some summary of what you found out.</p><p>The webinars will guide you in:</p><ul><li>the overview of different type of bugs and how to deal with them;</li><li>which tools you can use and for which type of bugs they’ll work better;</li><li>how to configure your <em>kgdb</em> kernel and start debugging (I never used <em>gdb -tui</em> previously, it’s great);</li><li>KASAN, KMSAN and other sanitizers — this is a masterpiece, which every kernel dev should use, really!</li><li>Syzkaller/syzbot — it’s another masterpiece, it’s a fuzzer which can create reproducers for the kernel bugs, not all of them — but, come on, it’s awesome;</li><li>ftrace facility — just no comments here -)</li></ul><p>You can complete all the tasks before starting to fix the real kernel bugs, or do them later. I personally did it before, which let me focus on the bugs later.</p><p>Next you will be on your own, you should search for the bugs in the different sources (<em>coccicheck</em>, <em>sparse</em>, <a href="https://syzkaller.appspot.com/upstream"><em>syzkaller</em></a> dashboard, etc) and fix them.</p><p>And of course you can ask for some help from the mentors! In my case the mentors were <strong>Shuah Khan</strong> and <strong>Ivan Orlov</strong>. They were holding weekly QA sessions during the mentorship program, replied to any questions from the mentees and did a great job in general.</p><p>Seems that 2023 was a lucky year for the mentees and our mentors organized a hackathon in which we should fix syzkaller bugs within some team. It was a good idea, although the hackathon concept is not really suitable to fix syzkaller/kernel bugs. But the main objective was to try doing teamwork.</p><p>I connected with some other mentees, we formed a team and named it BugBusters -) all <a href="https://www.imdb.com/title/tt0087332/">coincidences</a> here are random. For those who are interested in how we participated in this hackathon — here is the <a href="https://docs.google.com/presentation/d/1L9VXKB4Rw_iS1YZLdrpq5Y0t6r6Jyam16zHXREMzRrY/">link</a> to our report.</p><p>My personal experience for the bug-fixing part of the mentorship in a nutshell:</p><ol><li>as my initial goal I decided to deal with the bugs in core Linux subsystems, instead of dealing with documentation/scripts/tools/etc;</li><li>first I tried to find less complex type of bugs (no race conditions, no locking issues, only 100%-reproducible bugs);</li><li>next I moved to exploring bugs in subsystems I’m familiar with (it is <em>net/</em>, because another one is <em>security/</em> and it has no reported bugs);</li><li>as a last requirement I decided to check only the bugs with C repro available.</li></ol><p>So I explored the syzkaller dashboard with such requirements and made an attempt when the bug seemed suitable for me. Of course not each attempt was successful, but here are my results:</p><blockquote>Accepted patches:<br><a href="https://git.kernel.org/linus/a12bbb3cccf03b12847de0f7a6772127f90936ac">a12bbb3cccf03b12847de0f7a6772127f90936ac</a> xdp: Fix zero-size allocation warning in xskq_create()<br><a href="https://git.kernel.org/linus/1df83cbf23a27174aee6ea5e52462f03f7e48a10">1df83cbf23a27174aee6ea5e52462f03f7e48a10</a> selinux: prevent KMSAN warning in selinux_inet_conn_request()<br><a href="https://git.kernel.org/linus/d14eea09edf427fa36bd446f4a3271f99164202f">d14eea09edf427fa36bd446f4a3271f99164202f</a> net: core: remove unnecessary frame_sz check in bpf_xdp_adjust_tail()<br><a href="https://git.kernel.org/linus/59eeb232940515590de513b997539ef495faca9a">59eeb232940515590de513b997539ef495faca9a</a> drivers: net: prevent tun_build_skb() to exceed the packet size limit<br><a href="https://git.kernel.org/linus/cade5397e5461295f3cb87880534b6a07cafa427">cade5397e5461295f3cb87880534b6a07cafa427</a> fs/jfs: prevent double-free in dbUnmount() after failed jfs_remount()</blockquote><blockquote>Links to syzbot bugs I was able to fix:<br>Link[1]: <a href="https://syzkaller.appspot.com/bug?extid=fae676d3cf469331fc89">https://syzkaller.appspot.com/bug?extid=fae676d3cf469331fc89</a><br>Link[2]: <a href="https://syzkaller.appspot.com/bug?extid=b132693e925cbbd89e26">https://syzkaller.appspot.com/bug?extid=b132693e925cbbd89e26</a><br>Link[3]: <a href="https://syzkaller.appspot.com/bug?extid=f817490f5bd20541b90a">https://syzkaller.appspot.com/bug?extid=f817490f5bd20541b90a</a><br>Link[4]: <a href="https://syzkaller.appspot.com/bug?extid=6a93efb725385bc4b2e9">https://syzkaller.appspot.com/bug?extid=6a93efb725385bc4b2e9</a><br>Link[5]: <a href="https://syzkaller.appspot.com/bug?extid=9f06ddd18bf059dff2ad">https://syzkaller.appspot.com/bug?extid=9f06ddd18bf059dff2ad</a><br>Link[6]: <a href="https://syzkaller.appspot.com/bug?extid=90a11e6b1e810785c6ff">https://syzkaller.appspot.com/bug?extid=90a11e6b1e810785c6ff</a><br>Link[7]: <a href="https://syzkaller.appspot.com/bug?extid=47366a6b503c7edf6bbb">https://syzkaller.appspot.com/bug?extid=47366a6b503c7edf6bbb</a></blockquote><p>[1] and [2] represent the same issue in <em>net/xdp/</em> and were reproducible only on arm kernel. The interesting part here was that the syzbot repro didn’t trigger any issues on both x86/x86_64 and aarch64 kernels. But it was triggering on arm, so I used a cross-compiler to build the kernel and repro.c. Then using cross-gdb checked the values passed to the <em>struct_size()</em>. I found out that the number of entries passed from <em>copy_from_sockptr()</em> was high enough to return SIZE_MAX on the 32-bit arm kernel. The following code didn’t expect SIZE_MAX, aligned it to PAGE_SIZE which resulted in overflow and passing 0 to <em>vmalloc_user()</em> — e.g. zero-size allocation in <em>mm/vmalloc.c</em>.</p><p>[3] was an interesting warning in <em>net/core/filter.c</em> which originated from <em>drivers/net/tun.c</em>. In fact I found two issues here: 1) with the WARN_ON which was triggered by syzbot repro and 2) in <em>tun.c</em> in which the packet size limits might be exceeded for some cases (not reported by syzbot, but reproducible using the same repro and reduced packet size). During a nice discussion with netdevs they agreed that the actual fix for 1) will be to remove the WARN_ON() :). But I provided some testing results for the big packet sizes, some gdb and ftrace outputs. The fix for 2) was quite trivial, the biggest problem was to notice it in the <em>tun_get_user()</em> execution flow.</p><p>[4] was a double-free in <em>fs/jfs/jfs_dmap.c</em>. I used trace-cmd (ftrace) and figured out that the issue happened only after failing <em>jfs_remount()</em>. In a nutshell the syzkaller repro used the fault injection facility and failed some allocations. When some allocation fails in <em>jfs_remount()</em> — the double-free warning will be caught by KASAN.</p><p>[5] — [7] were actually about the similar issue in <em>fs/jfs/jfs_imap.c</em>, but their reproducers might trigger one or another double-free. Fix for the first double-free was already sent to the mailing list (by <strong>Liu Shixin</strong>), but not merged for some reason. I notified the maintainer (<strong>Dave Kleikamp</strong>) about it and complemented it with my own fix for the second double-free [4]. I also marked some syzbot bugs as duplicates, because 2 patches were fixing 4 syzbot bugs [4]-[7] and at least 5 more from the other branches (duplicates).</p><p>I also fixed 1 issue, which syzbot haven’t reported, but it was reported by KMSAN in <em>security/selinux/netlabel.c</em> with my own kernel config. Since it was a KMSAN issue, first of all I compiled the kernel using clang and corresponding changes to generate proper debuginfo. My own repro was really trivial — I just connected to my testing box using ssh as was described in <a href="https://github.com/google/syzkaller/blob/master/docs/syzbot_assets.md#run-a-c-reproducer">https://github.com/google/syzkaller/blob/master/docs/syzbot_assets.md#run-a-c-reproducer</a> and executed another repro. But actually KMSAN was complaining on every ssh connection, without doing something smart. Using gdb and kgdb I figured out that some variable (<em>nlbl_type</em>) was not initialized and passed to <em>security_net_peersid_resolve()</em> as a variable (not as a pointer). During my research I also verified that the initial code which was added in <a href="https://git.kernel.org/linus/220deb966ea5">https://git.kernel.org/linus/220deb966ea5</a> (v2.6.24) was not broken — there is a proper order of checks which could not result in anything bad.</p><h3>Summary</h3><p>My mentorship lasted 6 months, and the last couple of months were not so rich for experience (unfortunately).</p><p>I’m really excited how this whole thing was organized and how interesting it was. I must say that it’s not easy to get involved in it without some dev background. But if you have enough time (sometimes I don’t, my bad) the mentors will help you and answer all your questions — but you should be able to ask the right questions!</p><p>I really liked the (new) hackathon initiative, it allowed me to gain quite a different experience of teamwork as opposed to just doing some research alone. Although the hackathon was 1 week only, my team prepared for it and had a lot of fun. In fact, contribution to the Linux kernel might be a teamwork as well — you just need to find subsystems you like and maintainers/devs you are comfortable to work with.</p><p>And it seems I found the subsystem and devs during my mentorship. My communication with netdevs was really productive. I liked what questions they ask and which minor details they notice (like reasonable usage of optimizations — likely()/unlikely()). What I liked even more is that netdevs proposed two more possible issues to research after the initial one.</p><p>So I have some items to research next, but it’s another story: I already found out that the 1st issues was a feature (with a round-up of a new packet size), but the 2nd one is what I plan to do after the mentorship when I’ll research how to use pktgen in details.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce37aee844ee" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>