Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 9 Jun 2022 23:41:53 +0200 (CEST)
From:      Sysadmin Lists <sysadmin.lists@mailfence.com>
To:        freebsd-hackers@freebsd.org
Cc:        Neel Chauhan <nc@FreeBSD.org>
Subject:   Re: Potential USB bug with read() (while updating android-tools-adb)
Message-ID:  <1550558622.134608.1654810913427@ichabod.co-bxl>
In-Reply-To: <9b3dbdddb02e65c5ff4b3dc0f117c3c6@neelc.org>
References:  <9b3dbdddb02e65c5ff4b3dc0f117c3c6@neelc.org>

next in thread | previous in thread | raw e-mail | index | archive | help
> ----------------------------------------
> From: Neel Chauhan <nc@FreeBSD.org>
> Sent: Thu Jun 09 05:21:48 CEST 2022
> To: <freebsd-hackers@freebsd.org>
> Subject: Potential USB bug with read() (while updating android-tools-adb)
> 
> 
> 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@)
> 

I don't know if this adds a useful datapoint, but devel/android-tools-adb has
been broken for "adb push" on some devices for awhile. The device disconnects
immediately on any files larger than 0B (empty file). The solution posted
online was to downgrade the ports tree to the version that still worked (dated
Dec 11, 2017 IIRC). So, it's been broken on FreeBSD for awhile.


-- 
Sent with https://mailfence.com  
Secure and private email



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