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

Incorrect pointer alignment in _PyVectorcall_Function() of cpython/abstract.h #84233

Closed
cryptomilk mannequin opened this issue Mar 24, 2020 · 7 comments
Closed

Incorrect pointer alignment in _PyVectorcall_Function() of cpython/abstract.h #84233

cryptomilk mannequin opened this issue Mar 24, 2020 · 7 comments
Labels
3.8 only security fixes build The build process and cross-build topic-C-API

Comments

@cryptomilk
Copy link
Mannequin

cryptomilk mannequin commented Mar 24, 2020

BPO 40052
Nosy @mcepl, @encukou, @eamanu, @miss-islington, @cryptomilk
PRs
  • bpo-40052: Fix alignment issue in PyVectorcall_Function() #19133
  • bpo-40052: Replace misaligned type casting with proper unions. #19179
  • bpo-40052: Fix alignment issue in PyVectorcall_Function() #23999
  • [3.9] bpo-40052: Fix alignment issue in PyVectorcall_Function() (GH-23999) #24005
  • [3.8] bpo-40052: Fix alignment issue in PyVectorcall_Function() (GH-23999) #24120
  • 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 = <Date 2021-01-14.12:19:39.772>
    created_at = <Date 2020-03-24.06:58:12.620>
    labels = ['expert-C-API', 'build', '3.8']
    title = 'Incorrect pointer alignment in _PyVectorcall_Function() of cpython/abstract.h'
    updated_at = <Date 2021-01-14.12:19:39.771>
    user = 'https://github.com/cryptomilk'

    bugs.python.org fields:

    activity = <Date 2021-01-14.12:19:39.771>
    actor = 'petr.viktorin'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-01-14.12:19:39.772>
    closer = 'petr.viktorin'
    components = ['C API']
    creation = <Date 2020-03-24.06:58:12.620>
    creator = 'asn'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40052
    keywords = ['patch']
    message_count = 7.0
    messages = ['364919', '364954', '364963', '364977', '384033', '384410', '384945']
    nosy_count = 6.0
    nosy_names = ['mcepl', 'petr.viktorin', 'python-dev', 'eamanu', 'miss-islington', 'asn']
    pr_nums = ['19133', '19179', '23999', '24005', '24120']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'compile error'
    url = 'https://bugs.python.org/issue40052'
    versions = ['Python 3.8']

    @cryptomilk
    Copy link
    Mannequin Author

    cryptomilk mannequin commented Mar 24, 2020

    In file included from /builds/cryptomilk/pam_wrapper/src/python/pypamtest.c:21:
    In file included from /usr/include/python3.8/Python.h:147:
    In file included from /usr/include/python3.8/abstract.h:837:
    /usr/include/python3.8/cpython/abstract.h:91:11: error: cast from 'char *' to 'vectorcallfunc *' (aka 'struct _object *(**)(struct _object *, struct _object *const *, unsigned long, struct _object *)') increases required alignment from 1 to 8 [-Werror,-Wcast-align]
    ptr = (vectorcallfunc*)(((char *)callable) + offset);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1 error generated.

    The correct way to do it would be:

    union {
       char *data;
       vectorcallfunc *ptr;
    } vc;
    vc.data = (char *)callable + offset;
    return *vc.ptr;

    @cryptomilk cryptomilk mannequin added topic-C-API 3.8 only security fixes build The build process and cross-build labels Mar 24, 2020
    @eamanu
    Copy link
    Mannequin

    eamanu mannequin commented Mar 24, 2020

    Hi! I cannot reproduce the error. Could you provide the way to reproduce?

    thanks

    @cryptomilk
    Copy link
    Mannequin Author

    cryptomilk mannequin commented Mar 24, 2020

    clang -Werror -Wcast-align ...

    rpm -q clang9
    clang9-9.0.1-8.1.x86_64

    Does that help? Found in CI of

    https://gitlab.com/cwrap/pam_wrapper

    @cryptomilk
    Copy link
    Mannequin Author

    cryptomilk mannequin commented Mar 25, 2020

    I forgot, for detecting alignment issues or strict aliasing and this also falls under strict aliasing, you need to turn on optimizations.

    clang -O2 -Werror -Wcast-align ...

    @miss-islington
    Copy link
    Contributor

    New changeset 056c082 by Petr Viktorin in branch 'master':
    bpo-40052: Fix alignment issue in PyVectorcall_Function() (GH-23999)
    056c082

    @encukou
    Copy link
    Member

    encukou commented Jan 5, 2021

    New changeset 6e72ab9 by Miss Islington (bot) in branch '3.9':
    [3.9] bpo-40052: Fix alignment issue in PyVectorcall_Function() (GH-23999) (GH-24005)
    6e72ab9

    @encukou
    Copy link
    Member

    encukou commented Jan 12, 2021

    New changeset 187f76d by Petr Viktorin in branch '3.8':
    [3.8] bpo-40052: Fix alignment issue in PyVectorcall_Function() (GH-23999) (GH-24120)
    187f76d

    @encukou encukou closed this as completed Jan 14, 2021
    @encukou encukou closed this as completed Jan 14, 2021
    @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.8 only security fixes build The build process and cross-build topic-C-API
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants