OpenSSH 9.3p fails to build for Android
Asked Answered
V

1

1

I am trying to build OpenSSH for Android. I am using the current (as of this writing) version, which is 9.3p. Here what I do (mostly taken from Building OpenSSH for Android):

export ANDROID_NDK_ROOT=$ANDROID_HOME/ndk/21.0.6113669
export PATH=$PATH:$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin
cd ~/src

git clone [email protected]:openssh/openssh-portable.git
cd github-portable
git checkout V_9_3_P1
mkdir -p build/android-arm
autoreconf
# for the moment, build a stripped-down version without zlib and openssl
CHOST="arm-linux-androideabi" \
  CHOST2="armv7a-linux-androideabi17" \
  CC="${CHOST2}-clang" \
  CXX="${CHOST2}-clang++" \
  CFLAGS="-DHAVE_ATTRIBUTE__SENTINEL__=1" \
  CXXFLAGS="-DHAVE_ATTRIBUTE__SENTINEL__=1" \
  RANLIB="${CHOST}-ranlib" \
  LD="${CHOST}-ld" \
  AR="${CHOST}-ar" \
  ARFLAGS="cr" \
  CHOST="${CHOST}" \
  ./configure --host=arm-linux-androideabi --with-libs --without-zlib --without-openssl --prefix=$PWD/build/android-arm
make ssh

CFLAGS and CXXFLAGS are a workaround for another build issue, described in a comment to the question above, as well as https://github.com/android/ndk/issues/1362#issuecomment-712437159.

The build fails with an error, apparently due to some incompatibility between OpenSSH and one of the header files included from NDK:

armv7a-linux-androideabi26-clang -DHAVE_ATTRIBUTE__SENTINEL__=1 -pipe -Wunknown-warning-option -Qunused-arguments -Wall -Wpointer-arith -Wuninitialized -Wsign-compare -Wformat-security -Wsizeof-pointer-memaccess -Wno-pointer-sign -Wno-unused-result -Wimplicit-fallthrough -fno-strict-aliasing -mretpoline -D_FORTIFY_SOURCE=2 -ftrapv -fno-builtin-memset -fstack-protector-strong   -fPIC -I. -I.. -I. -I./..  -DHAVE_CONFIG_H -c bsd-misc.c
bsd-misc.c:392:7: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
bzero(void *b, size_t n)
      ^
bsd-misc.c:392:16: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
bzero(void *b, size_t n)
               ^
bsd-misc.c:392:1: error: at most one overload for a given name may lack the 'overloadable' attribute
bzero(void *b, size_t n)
^
/home/user149408/tools/android-sdk-linux_86/ndk/21.0.6113669/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/strings.h:61:23: note: expanded from macro 'bzero'
#define bzero(b, len) __bionic_bzero((b), (len))
                      ^
/home/user149408/tools/android-sdk-linux_86/ndk/21.0.6113669/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/strings.h:62:40: note: previous unmarked overload of function is here
static __inline__ __always_inline void __bionic_bzero(void* b, size_t len) {
                                       ^
bsd-misc.c:392:7: error: parameter name omitted
bzero(void *b, size_t n)
      ^
bsd-misc.c:392:16: error: parameter name omitted
bzero(void *b, size_t n)
               ^
bsd-misc.c:394:15: error: use of undeclared identifier 'b'
        (void)memset(b, 0, n);
                     ^
bsd-misc.c:394:21: error: use of undeclared identifier 'n'
        (void)memset(b, 0, n);
                           ^
2 warnings and 5 errors generated.
make[1]: *** [Makefile:106: bsd-misc.o] Error 1
make[1]: Leaving directory '/home/user149408/src/openssh-portable/openbsd-compat'
make: *** [Makefile:199: openbsd-compat/libopenbsd-compat.a] Error 2

Building natively for the host platform (Ubuntu 22.04 x86_64) works.

What’s up here, and what can I do about it?

Vallombrosa answered 31/5, 2023 at 20:12 Comment(0)
C
0

I've just built a successfully working ssh client of openssh-9.4p1. (With openssl-3.0.10 and ldns-1.8.3 because I need secure connections, but which is not relevant to this question...)

I suppose you should declare you have bzero(), because openbsd-compat/explicit_bzero.c needs bzero(). (explicit_bzero.c has 3 implementation of explicit_bzero(), one needs explicit_memset(), one needs memset_s(), one needs bzero(), and android does not have explicit_memset() nor memset_s())

So,

cat >zzconfig.cache <<EOF
ac_cv_func_mblen=yes
ac_cv_func_bzero=yes
ac_cv_have_decl_bzero=yes
ac_cv_member_struct_passwd_pw_gecos=no
EOF

(ac_cv_member_struct_passwd_pw_gecos=no is for building ssh client for ILP32. LP64 should not needs this but I've not checked LP64. See pwd.h somewhere in the sysroot.)

and do

configure --cache-file=`pwd`/zzconfig.cache ...

The problem is android bzero() is not a function but a function-like macro to __bionic_bzero(). So either need to fix this in openbsd-compat/explicit_bzero.c

static void (* volatile ssh_bzero)(void *, size_t) = bzero;

or add this in somewhere

#undef bzero
void bzero(void* b, size_t len) {
  __bionic_bzero(b, len);
}

The next problem you encounter I suppose is, getrrsetbyname(). There are two implementations of getrrsetbyname(), one needs libresolv, one needs ldns with SSL (or ldns having ldns_verify_trusted() function.) I use the latter because IIRC android does not have a working libresolv, and I actually already have the latter.

Lastly the build further needs getifaddrs() and freeifaddrs() but you can get them somewhere. I got mine from dhcpd for android.

And you have a working ssh client.

2024-01-31 I've little idea if my post is of any help, but anyway, today I built LP64 version of ssh client and found that, LP64 version of struct passwd does have pw_gecos member (so you need to set ac_cv_member_struct_passwd_pw_gecos=yes for LP64 build), but, the value of it is set to NULL, causing SEGV, at least on Android 8.0 device with uid = AID_SHELL (2000). So you need to fix the source like this.

diff -rup openssh-9.6p1/misc.c openssh-9.6p1-droid-p01/misc.c
--- openssh-9.6p1/misc.c        2023-12-18 23:59:50.000000000 +0900
+++ openssh-9.6p1-droid-p01/misc.c      2024-01-31 17:10:46.530066587 +0900
@@ -488,7 +488,7 @@ pwcopy(struct passwd *pw)
        copy->pw_name = xstrdup(pw->pw_name);
        copy->pw_passwd = xstrdup(pw->pw_passwd == NULL ? "*" : pw->pw_passwd);
 #ifdef HAVE_STRUCT_PASSWD_PW_GECOS
-       copy->pw_gecos = xstrdup(pw->pw_gecos);
+       copy->pw_gecos = xstrdup(pw->pw_gecos == NULL ? "null" : pw->pw_gecos);
 #endif
        copy->pw_uid = pw->pw_uid;
        copy->pw_gid = pw->pw_gid;
Clapboard answered 5/10, 2023 at 5:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.