Commit 0fdf41d
rust_binder: correctly handle FDA objects of length zero
Fix a bug where an empty FDA (fd array) object with 0 fds would cause an
out-of-bounds error. The previous implementation used `skip == 0` to
mean "this is a pointer fixup", but 0 is also the correct skip length
for an empty FDA. If the FDA is at the end of the buffer, then this
results in an attempt to write 8-bytes out of bounds. This is caught and
results in an EINVAL error being returned to userspace.
The pattern of using `skip == 0` as a special value originates from the
C-implementation of Binder. As part of fixing this bug, this pattern is
replaced with a Rust enum.
I considered the alternate option of not pushing a fixup when the length
is zero, but I think it's cleaner to just get rid of the zero-is-special
stuff.
The root cause of this bug was diagnosed by Gemini CLI on first try. I
used the following prompt:
> There appears to be a bug in @drivers/android/binder/thread.rs where
> the Fixups oob bug is triggered with 316 304 316 324. This implies
> that we somehow ended up with a fixup where buffer A has a pointer to
> buffer B, but the pointer is located at an index in buffer A that is
> out of bounds. Please investigate the code to find the bug. You may
> compare with @drivers/android/binder.c that implements this correctly.
Cc: stable@vger.kernel.org
Reported-by: DeepChirp <DeepChirp@outlook.com>
Closes: waydroid/waydroid#2157
Fixes: eafedbc ("rust_binder: add Rust Binder driver")
Tested-by: DeepChirp <DeepChirp@outlook.com>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Cherry-picked-for: https://gitlab.archlinux.org/archlinux/packaging/packages/linux/-/issues/1731 parent ed4bfee commit 0fdf41d
1 file changed
+34
-25
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
83 | 90 | | |
84 | 91 | | |
85 | 92 | | |
| |||
762 | 769 | | |
763 | 770 | | |
764 | 771 | | |
765 | | - | |
766 | | - | |
| 772 | + | |
767 | 773 | | |
768 | 774 | | |
769 | 775 | | |
| |||
807 | 813 | | |
808 | 814 | | |
809 | 815 | | |
810 | | - | |
| 816 | + | |
811 | 817 | | |
812 | | - | |
813 | 818 | | |
814 | 819 | | |
815 | 820 | | |
| |||
871 | 876 | | |
872 | 877 | | |
873 | 878 | | |
874 | | - | |
875 | | - | |
876 | | - | |
877 | | - | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
878 | 887 | | |
879 | 888 | | |
880 | | - | |
881 | | - | |
| 889 | + | |
| 890 | + | |
882 | 891 | | |
883 | 892 | | |
884 | | - | |
| 893 | + | |
885 | 894 | | |
886 | 895 | | |
887 | 896 | | |
| |||
890 | 899 | | |
891 | 900 | | |
892 | 901 | | |
893 | | - | |
| 902 | + | |
894 | 903 | | |
895 | 904 | | |
896 | 905 | | |
897 | 906 | | |
898 | | - | |
899 | | - | |
| 907 | + | |
| 908 | + | |
900 | 909 | | |
901 | 910 | | |
902 | 911 | | |
| |||
0 commit comments