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

Buffer overflow vulnerability in os.symlink on Windows (CVE-2018-1000117) #77182

Closed
zooba opened this issue Mar 5, 2018 · 14 comments
Closed
Assignees
Labels
3.7 (EOL) end of life 3.8 only security fixes OS-windows type-security A security issue

Comments

@zooba
Copy link
Member

zooba commented Mar 5, 2018

BPO 33001
Nosy @pfmoore, @vstinner, @larryhastings, @tjguk, @ned-deily, @zware, @eryksun, @zooba, @izbyshev, @miss-islington
PRs
  • bpo-33001: Minimal fix to prevent buffer overrun in os.symlink #5989
  • [3.6] bpo-33001: Minimal fix to prevent buffer overrun in os.symlink (GH-5989) #5990
  • [3.5] bpo-33001: Prevent buffer overrun in os.symlink (GH-5989) #5991
  • [3.4] bpo-33001: Prevent buffer overrun in os.symlink (GH-5989) #5992
  • [3.7] bpo-33001: Prevent buffer overrun in os.symlink (GH-5989) #5996
  • 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 = 'https://github.com/zooba'
    closed_at = <Date 2018-05-28.23:25:42.844>
    created_at = <Date 2018-03-05.18:04:42.615>
    labels = ['type-security', '3.7', '3.8', 'OS-windows']
    title = 'Buffer overflow vulnerability in os.symlink on Windows (CVE-2018-1000117)'
    updated_at = <Date 2019-05-10.18:06:59.274>
    user = 'https://github.com/zooba'

    bugs.python.org fields:

    activity = <Date 2019-05-10.18:06:59.274>
    actor = 'ned.deily'
    assignee = 'steve.dower'
    closed = True
    closed_date = <Date 2018-05-28.23:25:42.844>
    closer = 'steve.dower'
    components = ['Windows']
    creation = <Date 2018-03-05.18:04:42.615>
    creator = 'steve.dower'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 33001
    keywords = ['patch', 'security_issue']
    message_count = 14.0
    messages = ['313275', '313279', '313281', '313282', '313291', '313292', '313293', '313298', '313368', '313398', '313415', '316539', '316543', '317958']
    nosy_count = 10.0
    nosy_names = ['paul.moore', 'vstinner', 'larry', 'tim.golden', 'ned.deily', 'zach.ware', 'eryksun', 'steve.dower', 'izbyshev', 'miss-islington']
    pr_nums = ['5989', '5990', '5991', '5992', '5996']
    priority = 'critical'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'security'
    url = 'https://bugs.python.org/issue33001'
    versions = ['Python 3.4', 'Python 3.5', 'Python 3.6', 'Python 3.7', 'Python 3.8']

    @zooba
    Copy link
    Member Author

    zooba commented Mar 5, 2018

    On February 27th, 2018, the Python Security Response team was notified of a buffer overflow issue in the os.symlink() method on Windows. The issue affects all versions of Python between 3.2 and 3.6.4, including the 3.7 beta releases. It will be patched for the next releases of 3.4, 3.5, 3.6 and 3.7.

    Scripts may be vulnerable if they use os.symlink() on Windows and an attacker is able to influence the location where links are created. As os.symlink requires administrative privileges on most versions of Windows, exploits using this vulnerability are likely to achieve escalation of privilege.

    Besides applying the fix to CPython, scripts can also ensure that the length of each path argument is less than 260, and if the source is a relative path, that its combination with the destination is also shorter than 260 characters. That is:

    assert (len(src) < 260 and
            len(dest) < 260 and
            len(os.path.join(os.path.dirname(dest), src)) < 260)
    os.symlink(src, dest)
    

    Scripts that explicitly pass the target_is_directory argument as True are not vulnerable. Also, scripts on Python 3.5 that use bytes for paths are not vulnerable, because of a combination of stack layout and added parameter validation.

    I will be requesting a CVE for this once the patches are applied to maintenance branches, and then notifying the security-announce list. The patch has been reviewed by the PSRT and reporter, and while it prevents the buffer overflow, it does not raise any new errors or enable the use of long paths when creating symlinks.

    Many thanks to Alexey Izbyshev for the report, and helping us work through developing the patch.

    @zooba zooba added 3.7 (EOL) end of life 3.8 only security fixes labels Mar 5, 2018
    @zooba zooba self-assigned this Mar 5, 2018
    @zooba zooba added OS-windows type-security A security issue labels Mar 5, 2018
    @izbyshev
    Copy link
    Mannequin

    izbyshev mannequin commented Mar 5, 2018

    While judging by the source code it seems that bytes in 3.5 should be fine, I've got a crash with the latest binary from python.org:

    Python 3.5.4 (v3.5.4:3f56838, Aug  8 2017, 02:17:05) [MSC v.1900 64 bit (AMD64)]
     on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os
    >>> os.symlink(b'x\\' * 129, b'y\\' * 129)
    (Windows pop-up here)

    @izbyshev
    Copy link
    Mannequin

    izbyshev mannequin commented Mar 5, 2018

    As os.symlink requires administrative privileges on most versions of Windows

    The current implementation requires SeCreateSymbolicLinkPrivilege on ALL versions of Windows because users must pass an additional flag to CreateSymbolicLink to enable non-privileged symlinks on recent Windows 10, which os.symlink() doesn't do (see bpo-31512).

    @eryksun
    Copy link
    Contributor

    eryksun commented Mar 5, 2018

    > As os.symlink requires administrative privileges on most versions
    > of Windows

    The current implementation requires SeCreateSymbolicLinkPrivilege on
    ALL versions of Windows because users must pass an additional flag to
    CreateSymbolicLink to enable non-privileged symlinks on recent Windows
    10, which os.symlink() doesn't do (see bpo-31512).

    The change in Windows 10 to allow unprivileged creation of links will be supported implicitly in 3.7, but this change is more for convenience than necessity. SeCreateSymbolicLinkPrivilege can be granted to standard users and groups. On my own systems, I grant this privilege to the "Authenticated Users" (S-1-5-11) well-known group. This even allows administrators to create symbolic links without having to elevate.

    @zooba
    Copy link
    Member Author

    zooba commented Mar 5, 2018

    New changeset 6921e73 by Steve Dower in branch 'master':
    bpo-33001: Prevent buffer overrun in os.symlink (GH-5989)
    6921e73

    @zooba
    Copy link
    Member Author

    zooba commented Mar 5, 2018

    New changeset baa4507 by Steve Dower in branch '3.6':
    [3.6] bpo-33001: Prevent buffer overrun in os.symlink (GH-5989) (GH-5990)
    baa4507

    @zooba
    Copy link
    Member Author

    zooba commented Mar 5, 2018

    Patches are merged, except for the ones that belong to @larry.

    Thanks again Alexey for the final round of feedback!

    @miss-islington
    Copy link
    Contributor

    New changeset 96fdbac by Miss Islington (bot) in branch '3.7':
    bpo-33001: Prevent buffer overrun in os.symlink (GH-5989)
    96fdbac

    @zooba
    Copy link
    Member Author

    zooba commented Mar 7, 2018

    FYI, the CVE number for this issue is CVE-2018-1000117.

    @zooba zooba changed the title Buffer overflow vulnerability in os.symlink on Windows Buffer overflow vulnerability in os.symlink on Windows (CVE-2018-1000117) Mar 7, 2018
    @zooba
    Copy link
    Member Author

    zooba commented Mar 8, 2018

    Thanks, Victor!

    @larryhastings
    Copy link
    Contributor

    New changeset 77c02cd by larryhastings (Steve Dower) in branch '3.4':
    [3.4] bpo-33001: Prevent buffer overrun in os.symlink (GH-5989) (bpo-5992)
    77c02cd

    @larryhastings
    Copy link
    Contributor

    New changeset f381cfe by larryhastings (Steve Dower) in branch '3.5':
    [3.5] bpo-33001: Prevent buffer overrun in os.symlink (GH-5989) (bpo-5991)
    f381cfe

    @zooba
    Copy link
    Member Author

    zooba commented May 28, 2018

    Thanks Larry for merging the backports!

    @zooba zooba closed this as completed May 28, 2018
    @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
    3.7 (EOL) end of life 3.8 only security fixes OS-windows type-security A security issue
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants