-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Careful cleanup in spi_exit #180
base: master
Are you sure you want to change the base?
Careful cleanup in spi_exit #180
Conversation
Avoid deleting a cdev that was never added; or unregistering a netdev that was never registered. this fixes issue espressif#179: "When inserting linux spi driver as a module, failure to connect to a spi controller results in a crash"
|
Hello @drosen-taranawireless Thank you for taking efforts to make this project better. |
Hello @drosen-taranawireless Thank you once again for the submission of PR.
You can easily reproduce scenario using ESP32-C6 binary (if you have ESP32-C6) |
Hi Yogesh,
I wasn't able to reproduce the use-after-free condition that you sent - and
I don't have access to an ESP32-C6. Can you give me a little more detail
about what you think is happening, and also describe the steps to reproduce.
Thanks,
David Rosen
***@***.***)
…On Tue, Mar 14, 2023 at 6:17 AM Yogesh ***@***.***> wrote:
Hello @drosen-taranawireless <https://github.com/drosen-taranawireless>
Thank you once again for the submission of PR.
I tested your changes, but I think still corner cases are left.
***@***.***:~/h3/esp_hosted_fg/host/linux/host_control$ bash rpi_init.sh spi
Building for spi protocol
Mar 14 12:36:47 raspberrypi kernel: [ 152.073309] OF: overlay: WARNING: memory leak will occur if overlay removed, property: ***@***.******@***.***/status
rm -f *.out *.o
gcc -C -Wall --sysroot= -I/home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../../common/protobuf-c -I/home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../../common/include -I/home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../control_lib/include -I/home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../control_lib/src/include -I/home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../virtual_serial_if/include -I/home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../components/include -I/home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../port/include -I. /home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../../common/protobuf-c/protobuf-c/protobuf-c.c /home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../../common/esp_hosted_config.pb-c.c /home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../control_lib/src/ctrl_core.c /home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../control_lib/src/ctrl_api.c /home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../virtual_serial_if/src/serial_if.c /home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../components/src/esp_queue.c /home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../port/src/platform_wrapper.c ./test_utils.c -lpthread -lrt test.c -o test.out
gcc -C -Wall --sysroot= -fsanitize=undefined -fsanitize-address-use-after-scope -fsanitize-undefined-trap-on-error -fstack-protector-all -fstack-check -fsanitize=address -fsanitize=pointer-compare -fno-omit-frame-pointer -static-libasan -I/home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../../common/protobuf-c -I/home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../../common/include -I/home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../control_lib/include -I/home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../control_lib/src/include -I/home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../virtual_serial_if/include -I/home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../components/include -I/home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../port/include -I. /home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../../common/protobuf-c/protobuf-c/protobuf-c.c /home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../../common/esp_hosted_config.pb-c.c /home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../control_lib/src/ctrl_core.c /home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../control_lib/src/ctrl_api.c /home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../virtual_serial_if/src/serial_if.c /home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../../components/src/esp_queue.c /home/pi/h3/esp_hosted_fg/host/linux/host_control/c_support/../../port/src/platform_wrapper.c ./test_utils.c -lpthread -lrt stress.c -o stress.out -ggdb3 -g
rm -f commands.so *.o
gcc -C -Wall -I/home/pi/h3/esp_hosted_fg/host/linux/host_control/python_support/../../../../common/protobuf-c -I/home/pi/h3/esp_hosted_fg/host/linux/host_control/python_support/../../../../common/include -I/home/pi/h3/esp_hosted_fg/host/linux/host_control/python_support/../../../control_lib/include -I/home/pi/h3/esp_hosted_fg/host/linux/host_control/python_support/../../../control_lib/src/include -I/home/pi/h3/esp_hosted_fg/host/linux/host_control/python_support/../../../virtual_serial_if/include -I/home/pi/h3/esp_hosted_fg/host/linux/host_control/python_support/../../../components/include -I/home/pi/h3/esp_hosted_fg/host/linux/host_control/python_support/../../port/include -I. /home/pi/h3/esp_hosted_fg/host/linux/host_control/python_support/../../../../common/protobuf-c/protobuf-c/protobuf-c.c /home/pi/h3/esp_hosted_fg/host/linux/host_control/python_support/../../../../common/esp_hosted_config.pb-c.c /home/pi/h3/esp_hosted_fg/host/linux/host_control/python_support/../../../control_lib/src/ctrl_core.c /home/pi/h3/esp_hosted_fg/host/linux/host_control/python_support/../../../control_lib/src/ctrl_api.c /home/pi/h3/esp_hosted_fg/host/linux/host_control/python_support/../../../virtual_serial_if/src/serial_if.c /home/pi/h3/esp_hosted_fg/host/linux/host_control/python_support/../../../components/src/esp_queue.c /home/pi/h3/esp_hosted_fg/host/linux/host_control/python_support/../../port/src/platform_wrapper.c -lrt -lpthread -o commands.so -shared -fPIC
Mar 14 12:37:00 raspberrypi kernel: [ 165.004042] ------------[ cut here ]------------
Mar 14 12:37:00 raspberrypi kernel: [ 165.004083] WARNING: CPU: 2 PID: 1793 at lib/refcount.c:28 refcount_warn_saturate+0x13c/0x174
Mar 14 12:37:00 raspberrypi kernel: [ 165.004098] refcount_t: underflow; use-after-free.
Mar 14 12:37:00 raspberrypi kernel: [ 165.004110] Modules linked in: cmac bnep esp32_spi(O-) bluetooth ecdh_generic ecc fuse binfmt_misc spidev brcmfmac brcmutil cfg80211 rfkill v3d raspberrypi_hwmon gpu_sched vc4 bcm2835_isp(C) bcm2835_codec(C) bcm2835_v4l2(C) v4l2_mem2mem cec bcm2835_mmal_vchiq(C) videobuf2_dma_contig videobuf2_vmalloc spi_bcm2835 drm_kms_helper videobuf2_memops videobuf2_v4l2 videobuf2_common drm drm_panel_orientation_quirks snd_bcm2835(C) videodev mc vc_sm_cma(C) snd_soc_core snd_compress snd_pcm_dmaengine snd_pcm snd_timer rpivid_mem snd syscopyarea sysfillrect sysimgblt fb_sys_fops backlight nvmem_rmem uio_pdrv_genirq uio ip_tables x_tables ipv6
Mar 14 12:37:00 raspberrypi kernel: [ 165.004470] CPU: 2 PID: 1793 Comm: rmmod Tainted: G C O 5.10.103-v7l+ #1529
Mar 14 12:37:00 raspberrypi kernel: [ 165.004481] Hardware name: BCM2711
Mar 14 12:37:00 raspberrypi kernel: [ 165.004490] Backtrace:
Mar 14 12:37:00 raspberrypi kernel: [ 165.004507] [<c0b875f0>] (dump_backtrace) from [<c0b87984>] (show_stack+0x20/0x24)
Mar 14 12:37:00 raspberrypi kernel: [ 165.004520] r7:ffffffff r6:00000000 r5:60000013 r4:c12e6fd8
Mar 14 12:37:00 raspberrypi kernel: [ 165.004533] [<c0b87964>] (show_stack) from [<c0b8bd74>] (dump_stack+0xcc/0xf8)
Mar 14 12:37:00 raspberrypi kernel: [ 165.004549] [<c0b8bca8>] (dump_stack) from [<c0220c8c>] (__warn+0xfc/0x114)
Mar 14 12:37:00 raspberrypi kernel: [ 165.004561] r10:00000081 r9:00000009 r8:c0735864 r7:0000001c r6:00000009 r5:c0735864
Mar 14 12:37:00 raspberrypi kernel: [ 165.004572] r4:c0e67324 r3:c1205094
Mar 14 12:37:00 raspberrypi kernel: [ 165.004583] [<c0220b90>] (__warn) from [<c0b88128>] (warn_slowpath_fmt+0xa4/0xd8)
Mar 14 12:37:00 raspberrypi kernel: [ 165.004594] r7:0000001c r6:c0e67324 r5:c1205048 r4:c0e67360
Mar 14 12:37:00 raspberrypi kernel: [ 165.004607] [<c0b88088>] (warn_slowpath_fmt) from [<c0735864>] (refcount_warn_saturate+0x13c/0x174)
Mar 14 12:37:00 raspberrypi kernel: [ 165.004620] r9:c426c000 r8:c0200204 r7:00000081 r6:00000000 r5:00000000 r4:bf220350
Mar 14 12:37:00 raspberrypi kernel: [ 165.004635] [<c0735728>] (refcount_warn_saturate) from [<c0775cf0>] (kobject_put+0xf4/0xfc)
Mar 14 12:37:00 raspberrypi kernel: [ 165.004650] [<c0775bfc>] (kobject_put) from [<c0445130>] (cdev_del+0x38/0x3c)
Mar 14 12:37:00 raspberrypi kernel: [ 165.004661] r7:00000081 r6:00000000 r5:00000000 r4:bf220350
Mar 14 12:37:00 raspberrypi kernel: [ 165.004685] [<c04450f8>] (cdev_del) from [<bf21e0b0>] (esp_serial_cleanup+0x30/0xa4 [esp32_spi])
Mar 14 12:37:00 raspberrypi kernel: [ 165.004697] r5:00000000 r4:bf22034c
Mar 14 12:37:00 raspberrypi kernel: [ 165.004716] [<bf21e080>] (esp_serial_cleanup [esp32_spi]) from [<bf21d224>] (spi_exit+0xb0/0x12c [esp32_spi])
Mar 14 12:37:00 raspberrypi kernel: [ 165.004728] r5:00000000 r4:bf2202c8
Mar 14 12:37:00 raspberrypi kernel: [ 165.004746] [<bf21d174>] (spi_exit [esp32_spi]) from [<bf21dbbc>] (esp_deinit_interface_layer+0x18/0x1c [esp32_spi])
Mar 14 12:37:00 raspberrypi kernel: [ 165.004758] r5:bf220040 r4:c1205048
Mar 14 12:37:00 raspberrypi kernel: [ 165.004775] [<bf21dba4>] (esp_deinit_interface_layer [esp32_spi]) from [<bf21eabc>] (esp_exit+0x10/0x554 [esp32_spi])
Mar 14 12:37:00 raspberrypi kernel: [ 165.004796] [<bf21eaac>] (esp_exit [esp32_spi]) from [<c02cc798>] (sys_delete_module+0x160/0x238)
Mar 14 12:37:00 raspberrypi kernel: [ 165.004811] [<c02cc638>] (sys_delete_module) from [<c0200040>] (ret_fast_syscall+0x0/0x28)
Mar 14 12:37:00 raspberrypi kernel: [ 165.004822] Exception stack(0xc426dfa8 to 0xc426dff0)
Mar 14 12:37:00 raspberrypi kernel: [ 165.004833] dfa0: 0085c2a0 befa3bb0 0085c2dc 00000800 ba66af00 ba66af00
Mar 14 12:37:00 raspberrypi kernel: [ 165.004845] dfc0: 0085c2a0 befa3bb0 00000002 00000081 befa3e9f 0085c2a0 00000000 0003fce8
Mar 14 12:37:00 raspberrypi kernel: [ 165.004857] dfe0: 0003ff88 befa3b64 00022bb8 b6c56fbc
Mar 14 12:37:00 raspberrypi kernel: [ 165.004866] r6:00000002 r5:befa3bb0 r4:0085c2a0
Mar 14 12:37:00 raspberrypi kernel: [ 165.004876] ---[ end trace cd28ea8b7af4ba6d ]---
***@***.***:~/h3/esp_hosted_fg/host/linux/host_control$ git log
--oneline |head -3
595d76b Careful cleanup in spi_exit
3dee7b1 Add ESP32-C6 API support for Linux and MCU <-- same as 09739e5
<09739e5>
(updated commit cause of force push)
fe0b105
<fe0b105>
Merge branch 'pull_req_185' into 'master'
You can easily reproduce scenario using ESP32-C6 binary (if you have
ESP32-C6)
c6_crash2.tgz
<https://github.com/espressif/esp-hosted/files/10968745/c6_crash2.tgz>
with above git log hierarchy
—
Reply to this email directly, view it on GitHub
<#180 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A4QYN7KJKCM4DTUZYG6MNTTW4BVXFANCNFSM6AAAAAASRNDU5I>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
- create and maintain serial driver /dev/esps0 from kernel module - removed serial creation and destroy from rpi_init.sh - closes PR #71 - closes PR #81 - closes PR #180 Co-authored-by: Yunhao Tian <t123yh@outlook.com> Co-authored-by: ljgabc <lee@wondertechlabs.com> Co-authored-by: David Rosen <drosen@taranawireless.com> Co-authored-by: Yogesh Mantri <yogesh.mantri@espressif.com>
Avoid deleting a cdev that was never added; or unregistering a netdev that was never registered. this fixes issue #179: "When inserting linux spi driver as a module, failure to connect to a spi controller results in a crash"