Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 08 Jun 2022 20:21:48 -0700
From:      Neel Chauhan <nc@FreeBSD.org>
To:        freebsd-hackers@freebsd.org
Subject:   Potential USB bug with read() (while updating android-tools-adb)
Message-ID:  <9b3dbdddb02e65c5ff4b3dc0f117c3c6@neelc.org>

next in thread | raw e-mail | index | archive | help
Hi hackers@,

While attempting to update android-tools-(fastboot/adb) to a newer 
version, I noticed a potential bug with the FreeBSD USB subsystem.

After two reads from a particular function in a USB device, read() reads 
0 bytes even with it should read 8 bytes and returns 0 respectively 
instead of 8.

The branch is: 
https://github.com/neelchauhan/freebsd-android-tools/tree/fbsd-31.0.3p1

The offending lines are:
vendor/adb/client/commandline.cpp:928 (ReadFdExactly call)
vendor/adb/adb_io.cpp:83 (adb_read call)
vendor/adb/sysdeps.h:526 (adb_read definition, this calls read())

This happens when I attempt to flash LineageOS 19.1 (Android Custom ROM) 
to a Google Pixel 3 smartphone via the so-called "recovery", which is 
the "test" device used to test if this port works (my main device, a 
Google Pixel 6 Pro while rooted can't be used since I'm not willing to 
live without a phone).

On Android, recoveries are used to update, root, or replace an Android 
installation. The `adb sideload` in the recovery causes read() to fail 
prematurely, whereas `adb push` in a recovery works perfectly.

However, LineageOS requires the "sideload" function to install on many 
devices, and I don't want a broken port in the Ports tree either.

On FreeBSD, this exact adb_read() routine works fine on other `adb` 
calls. On Linux (or macOS when I had a M1 Mac Mini before donating it to 
kevans@), `adb sideload` works perfectly, period.

I doubt most of you are rooted Android users, so if you need help 
understanding how Android flashing works feel free to ping me, I'm no 
"expert" either but have been doing this for 8+ years.

This error also happens with the Ports version, which is why I initially 
wanted to update.

Is there anything FreeBSD does in its USB implementation that's funky, 
or even in libusb? Especially in the last 2-3 year? Or is it more adb 
issues.

I am using an AMD Ryzen 5800X-based HP Omen 30L running FreeBSD 
14.0-CURRENT with Git revision 0817c8dc2a4 (May 14), but this also 
happens on other Intel-based and AMD-based systems, with both USB-A and 
USB-C Ports.

I'm not *really* a kernel person, and not at all a USB hacker. I'll 
probably update my CURRENT but this issue has been happening for 2 or so 
years now and rebooting into Linux USBs isn't exactly fun to flash my 
Android.

-Neel (nc@)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9b3dbdddb02e65c5ff4b3dc0f117c3c6>