Neo-Backup icon indicating copy to clipboard operation
Neo-Backup copied to clipboard

[Regression Bug] suCommand fails on devices without su -c support

Open hongwen000 opened this issue 1 year ago • 2 comments

Bug Report Submission

[Bug] suCommand fails on devices without su -c support

Description In the 8.2.1 version, the application was updated to support non-magisk SU implementations (su 0). The corresponding code was:

val suCommand get() =
    if (isMountMaster)
        "su --mount-master 0"
    else
        "su 0"

However, the current code has changed to:

var suCommand: List<String> = listOf()
    get() {
        if (field.isEmpty()) {
            field = when {
                hasNsEnter -> listOf(
                    "su",
                    "-c",
                    "nsenter --mount=/proc/1/ns/mnt sh"
                )
                hasMountMasterOption -> listOf("su", "--mount-master")
                else -> listOf("su")
            }
        }
        return field
    }

This change causes failures on devices that do not support su -c. I am using AOSP's native su.

Steps To Reproduce

  1. Use a device with AOSP's native su.
  2. Try to backup the apk and data of an app, then failes and saying su -c is not supported.

Expected behavior Commands should execute successfully on devices that do not support su -c, similar to the behavior in version 8.2.1.

Screenshots N/A

System Information

  • Device: sunfish
  • Android Version: [version]
  • ROM: AOSP
  • App's Version: 8.3.6

Additional Notes

  • The issue persists in the latest GitHub version.

Possible Solution Revert to the logic used in version 8.2.1 for suCommand or implement a check to avoid using -c if the device does not support it. Here is a suggested modification:

val suCommand: List<String> by lazy {
    when {
        hasNsEnter -> listOf(
            "su",
            "0",
            "nsenter",
            "--mount=/proc/1/ns/mnt",
            "sh"
        )
        hasMountMasterOption -> listOf("su", "--mount-master", "0")
        else -> listOf("su", "0")
    }
}

Thanks for reporting.

hongwen000 avatar Jul 03 '24 08:07 hongwen000

su information on my device:

sunfish:/ # su --help
usage: su [WHO [COMMAND...]]

Switch to WHO (default 'root') and run the given COMMAND (default sh).

WHO is a comma-separated list of user, group, and supplementary groups
in that order.

hongwen000 avatar Jul 03 '24 08:07 hongwen000

the latest pumpkins (see Telegram group, pinned messages of Bug Reports & Feature Requests) have made the suCommand editable... it is tried first, so if it works (which means some tests are successful, which is rudimentary for now), it is taken. So this should work for all cases, you just have to ensure that root commands work like expected.

Note, the commands are piped at stdin into that running shell/su/whatever. It is usually necessary to provide the nsenter functionality, either your su does it by default or it must have an option like --mount-master that handles the mount namespace (or your Android is old..).

suCommand is executed by libsu as the shell and also by NB itself for the tar commands (to be able to pipe date in and out).

hg42 avatar Oct 08 '24 23:10 hg42

Late update:

You can install busybox with selinux support and it should contain nsenter applet. meefik's busybox had this since 2018. osmOsis made busybox-ndk which supports systemless installation through magisk also supports it. If you don't want to install/symlink, you can also use command:

su -c '/sdcard/bin/busybox nsenter --mount=/proc/1/ns/mnt sh'

where busybox binary is copied to /sdcard/bin directory

https://github.com/NeoApplications/Neo-Backup/issues/940#issuecomment-3166562827

sheikhmishar avatar Aug 31 '25 14:08 sheikhmishar