Re: [PATCH] driver: iio: add missing checks on iio_info's callback access

From: Nuno Sá
Date: Wed May 29 2024 - 07:23:41 EST


On Wed, 2024-05-29 at 12:07 +0200, Julien Stephan wrote:
> Some callbacks from iio_info structure are accessed without any check, so
> if a driver doesn't implement them trying to access the corresponding
> sysfs entries produce a kernel oops such as:
>
> [ 2203.527791] Unable to handle kernel NULL pointer dereference at virtual address
> 00000000 when execute
> [ 2203.535795] [00000000] *pgd=01e70831, *pte=00000000, *ppte=00000000
> [ 2203.540822] Internal error: Oops: 80000007 [#1] PREEMPT SMP ARM
> [ 2203.552078] CPU: 0 PID: 1286 Comm: cat Not tainted 6.9.0-rc5-ad7380x-mainline-
> g9bf895a40063-dirty #226
> [ 2203.560079] Hardware name: Xilinx Zynq Platform
> [ 2203.563300] PC is at 0x0
> [ 2203.564523] LR is at iio_read_channel_info_avail+0x48/0xd8
> [ 2203.568716] pc : [<00000000>]    lr : [<c07b52e4>]    psr: a0000013
> [ 2203.573672] sp : e0bade60  ip : 5e861799  fp : 00000001
> [ 2203.577586] r10: c2dcd298  r9 : 00400cc0  r8 : c2dc6000
> [ 2203.581501] r7 : c4339008  r6 : c2dc6000  r5 : 00000000  r4 : c1003fc8
> [ 2203.586718] r3 : e0bade70  r2 : e0bade68  r1 : bf00ac88  r0 : c4339000
> [ 2203.591935] Flags: NzCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment none
> [ 2203.597761] Control: 18c5387d  Table: 01db804a  DAC: 00000051
> [ 2203.602194] Register r0 information: slab kmalloc-1k start c4339000 pointer
> offset 0 size 1024
> [ 2203.609520] Register r1 information: 2-page vmalloc region starting at
> 0xbf00a000 allocated at load_module+0x704/0x1954
> [ 2203.619016] Register r2 information: 2-page vmalloc region starting at
> 0xe0bac000 allocated at kernel_clone+0xb8/0x368
> [ 2203.628417] Register r3 information: 2-page vmalloc region starting at
> 0xe0bac000 allocated at kernel_clone+0xb8/0x368
> [ 2203.637808] Register r4 information: non-slab/vmalloc memory
> [ 2203.642166] Register r5 information: NULL pointer
> [ 2203.645559] Register r6 information: slab kmalloc-4k start c2dc6000 pointer
> offset 0 size 4096
> [ 2203.652886] Register r7 information: slab kmalloc-1k start c4339000 pointer
> offset 8 size 1024
> [ 2203.660211] Register r8 information: slab kmalloc-4k start c2dc6000 pointer
> offset 0 size 4096
> [ 2203.667537] Register r9 information: non-paged memory
> [ 2203.671278] Register r10 information: slab vm_area_struct start c2dcd280 pointer
> offset 24 size 80
> [ 2203.678951] Register r11 information: non-paged memory
> [ 2203.682779] Register r12 information: non-paged memory
> [ 2203.686607] Process cat (pid: 1286, stack limit = 0x354430a3)
> [ 2203.691052] Stack: (0xe0bade60 to 0xe0bae000)
> [ 2203.694105] de60: e0bade6c 00000019 c105fe40 00000001 00000002 5e861799 c4309ec0
> c07b529c
> [ 2203.700979] de80: c411b200 c051f1e4 c0b48d30 c2dcd280 c411b200 c02c1fb8 c2dcd280
> 00020000
> [ 2203.707853] dea0: e0badf20 c0b12d88 7ffff000 c026c944 c1003fc8 00000000 c2dcd2a8
> e0badf08
> [ 2203.714728] dec0: b6eaa000 c0206480 00000001 e0badfb0 c2dcda00 c1003fc8 c1e46d80
> c02c0ba0
> [ 2203.721602] dee0: c0b12d88 e0badf78 b6eab000 00000000 00000000 c0240114 00000a55
> c1dbadb8
> [ 2203.728476] df00: c1dbadb8 00000000 00000000 00000000 b6eab000 00020000 00000001
> 00000000
> [ 2203.735342] df20: c1e46d80 00000000 00000000 00000000 00000000 00000000 00000000
> 00000000
> [ 2203.742208] df40: 00000000 00000000 00000000 5e861799 c1003fc8 c1003fc8 c1e46d80
> 00000000
> [ 2203.749074] df60: 00000000 c1e46d80 b6eab000 00020000 00000000 c0240a80 00000000
> 00000000
> [ 2203.755949] df80: 00028008 5e861799 00000003 b6f10f80 7ff00000 00000003 c01002c4
> c6716e80
> [ 2203.762814] dfa0: 00000003 c0100060 00000003 b6f10f80 00000003 b6eab000 00020000
> 00000000
> [ 2203.769680] dfc0: 00000003 b6f10f80 7ff00000 00000003 00000003 00000000 00020000
> 00000000
> [ 2203.776546] dfe0: b6e1bc88 bed80958 b6e1bc94 b6e1bcb0 60000010 00000003 00000000
> 00000000
> [ 2203.783416] Call trace:
> [ 2203.783429]  iio_read_channel_info_avail from dev_attr_show+0x18/0x48
> [ 2203.789807]  dev_attr_show from sysfs_kf_seq_show+0x90/0x120
> [ 2203.794181]  sysfs_kf_seq_show from seq_read_iter+0xd0/0x4e4
> [ 2203.798555]  seq_read_iter from vfs_read+0x238/0x2a0
> [ 2203.802236]  vfs_read from ksys_read+0xa4/0xd4
> [ 2203.805385]  ksys_read from ret_fast_syscall+0x0/0x54
> [ 2203.809135] Exception stack(0xe0badfa8 to 0xe0badff0)
> [ 2203.812880] dfa0:                   00000003 b6f10f80 00000003 b6eab000 00020000
> 00000000
> [ 2203.819746] dfc0: 00000003 b6f10f80 7ff00000 00000003 00000003 00000000 00020000
> 00000000
> [ 2203.826619] dfe0: b6e1bc88 bed80958 b6e1bc94 b6e1bcb0
> [ 2203.830363] Code: bad PC value
> [ 2203.832695] ---[ end trace 0000000000000000 ]---
>
> Signed-off-by: Julien Stephan <jstephan@xxxxxxxxxxxx>
> ---

I think you should crop the splat on the commit message only with the pertinent info.
With that,

Reviewed-by: Nuno Sa <nuno.sa@xxxxxxxxxx>