Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback to dev_urandom doesn't work when py_getrandom returns -1 #76761

Open
jernejs mannequin opened this issue Jan 17, 2018 · 5 comments
Open

Fallback to dev_urandom doesn't work when py_getrandom returns -1 #76761

jernejs mannequin opened this issue Jan 17, 2018 · 5 comments
Labels
build The build process and cross-build

Comments

@jernejs
Copy link
Mannequin

jernejs mannequin commented Jan 17, 2018

BPO 32580
Nosy @vstinner, @jernejs
Files
  • random_fallback.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2018-01-17.13:11:08.071>
    labels = ['build']
    title = "Fallback to dev_urandom doesn't work when py_getrandom returns -1"
    updated_at = <Date 2018-01-17.20:52:10.985>
    user = 'https://github.com/jernejs'

    bugs.python.org fields:

    activity = <Date 2018-01-17.20:52:10.985>
    actor = 'jernejs'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Build']
    creation = <Date 2018-01-17.13:11:08.071>
    creator = 'jernejs'
    dependencies = []
    files = ['47389']
    hgrepos = []
    issue_num = 32580
    keywords = ['patch']
    message_count = 5.0
    messages = ['310158', '310162', '310196', '310197', '310206']
    nosy_count = 2.0
    nosy_names = ['vstinner', 'jernejs']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue32580'
    versions = ['Python 3.5', 'Python 3.6']

    @jernejs
    Copy link
    Mannequin Author

    jernejs mannequin commented Jan 17, 2018

    I'm playing with Gentoo in LXC running on ARM-based QNAP NAS, and when trying to compile Python 3.5.4, the build failed with "Fatal Python error: failed to get random numbers to initialize Python" (full details at https://forums.gentoo.org/viewtopic-p-8172124.html ).

    glibc in the environment is 2.25 (supports getrandom), while kernel is 3.10 (doesn't support getrandom).

    Looking at random.c, pyurandom returns -1 instead of falling back to dev_urandom when py_getrandom returns -1, so the attached fix is simple.

    @jernejs jernejs mannequin added the build The build process and cross-build label Jan 17, 2018
    @vstinner
    Copy link
    Member

    I'm playing with Gentoo in LXC running on ARM-based QNAP NAS, and when trying to compile Python 3.5.4, the build failed with "Fatal Python error: failed to get random numbers to initialize Python" (full details at https://forums.gentoo.org/viewtopic-p-8172124.html ).

    I'm surprised. Python 3.5.4 does contain my latest fix: commit 035ba5d (bpo-29157).

    Looking at random.c, pyurandom returns -1 instead of falling back to dev_urandom when py_getrandom returns -1, so the attached fix is simple.

    Ignoring failures is not a good idea.

    What is the result of the getrandom() function?

    glibc in the environment is 2.25 (supports getrandom), while kernel is 3.10 (doesn't support getrandom).

    I expect n < 0 with errno = ENOSYS: py_getrandom() should return 0 in this case, not -1.

    @jernejs
    Copy link
    Mannequin Author

    jernejs mannequin commented Jan 17, 2018

    OK, looks like Qnap is doing something weird there - calls to getrandom result in EFAULT, which results in . PHP had the same problem: https://bugs.php.net/bug.php?id=75409

    Changing "if (errno == ENOSYS || errno == EPERM) {" to "if (errno == ENOSYS || errno == EPERM || errno == EFAULT) {" also works.

    @vstinner
    Copy link
    Member

    OK, looks like Qnap is doing something weird there - calls to getrandom result in EFAULT

    Aha, first time that I see this error on getrandom().

    Is it a kernel change? A libc change? Is Qnap a kind of sandbox?

    @jernejs
    Copy link
    Mannequin Author

    jernejs mannequin commented Jan 17, 2018

    Qnap is a NAS, and while I'm running Gentoo inside LXC, EFAULT is returned by getrandom syscall even in the host OS. The model I'm doing this on is TS-228, uname -a of the host OS reports:

    Linux qnap 3.10.20-al-2.5.3 #67 SMP PREEMPT Sat Dec 30 04:29:34 CST 2017 armv7l unknown

    This is with the latest firmware installed as of this writing - 4.3.4.0435 (30.12.2017).

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    build The build process and cross-build
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant