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

Fix Bluetooth address parser #62764

Closed
mmaker mannequin opened this issue Jul 26, 2013 · 17 comments
Closed

Fix Bluetooth address parser #62764

mmaker mannequin opened this issue Jul 26, 2013 · 17 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@mmaker
Copy link
Mannequin

mmaker mannequin commented Jul 26, 2013

BPO 18564
Nosy @pitrou, @vstinner, @mmaker, @serhiy-storchaka, @zooba, @csabella
PRs
  • gh-62764: Fix integer overflow in socketmodule. #12864
  • Files
  • btoverflow.patch
  • issue18564.1.patch
  • issue18564.2.patch
  • issue18564.3.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 2013-07-26.17:59:05.783>
    labels = ['extension-modules', '3.8', 'type-bug', '3.7']
    title = 'Fix Bluetooth address parser'
    updated_at = <Date 2019-05-26.17:59:02.673>
    user = 'https://github.com/mmaker'

    bugs.python.org fields:

    activity = <Date 2019-05-26.17:59:02.673>
    actor = 'maker'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Extension Modules']
    creation = <Date 2013-07-26.17:59:05.783>
    creator = 'maker'
    dependencies = []
    files = ['31041', '31056', '35112', '35146']
    hgrepos = []
    issue_num = 18564
    keywords = ['patch']
    message_count = 16.0
    messages = ['193736', '193795', '196305', '196306', '196309', '217453', '217664', '217665', '217825', '218128', '220189', '339896', '340421', '340444', '340676', '340694']
    nosy_count = 8.0
    nosy_names = ['pitrou', 'vstinner', 'Arfrever', 'neologix', 'maker', 'serhiy.storchaka', 'steve.dower', 'cheryl.sabella']
    pr_nums = ['12864']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue18564'
    versions = ['Python 3.7', 'Python 3.8']

    @mmaker
    Copy link
    Mannequin Author

    mmaker mannequin commented Jul 26, 2013

    In Modules/socketmodule.c , the bluetooth address supplied is vulnerable to integer overflow.

    Attaching patch and a couple of tests, which should be considered as a step forward in bpo-7687.

    @mmaker mmaker mannequin added extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error labels Jul 26, 2013
    @pitrou
    Copy link
    Member

    pitrou commented Jul 27, 2013

    Instead of writing try / except / self.fail, you could simply use the context manager form of assertRaises.

    @mmaker
    Copy link
    Mannequin Author

    mmaker mannequin commented Aug 27, 2013

    Ping.

    @pitrou
    Copy link
    Member

    pitrou commented Aug 27, 2013

    Ah, haven't you seen Charles-François' comments on the review tool?
    Click on the "review" link next to your patch :-)

    @mmaker
    Copy link
    Mannequin Author

    mmaker mannequin commented Aug 27, 2013

    oops, didn't see :) thanks.

    @pitrou
    Copy link
    Member

    pitrou commented Apr 28, 2014

    Michele, do you plan to update this patch?

    @pitrou
    Copy link
    Member

    pitrou commented Apr 30, 2014

    Interestingly, the tests are skipped here (Linux 3.11.0-20-generic). For some reason my socket module is built without bluetooth support (HAVE_BLUETOOTH_BLUETOOTH_H and HAVE_BLUETOOTH_H are both undefined).

    @pitrou
    Copy link
    Member

    pitrou commented Apr 30, 2014

    Ah, I had to install libbluetooth-dev. Sorry for the noise.

    @mmaker
    Copy link
    Mannequin Author

    mmaker mannequin commented May 3, 2014

    Interestingly, <bluetooth/bluetooth.h> implements a function for parsing bluetooth addresses, but it's completely broken.
    <https://git.kernel.org/cgit/bluetooth/bluez.git/tree/lib/bluetooth.c#n83\>
    It would be much much more elegant to use str2ba() in our source code though.

    I am thinking about patching it there and then open another ticket here in order to adopt str2ba(). This way we can close this ticket for now.
    Does this sound reasonable to you, Antoine?

    @pitrou
    Copy link
    Member

    pitrou commented May 8, 2014

    I am thinking about patching it there and then open another ticket
    here in order to adopt str2ba(). This way we can close this ticket for > now.

    Well, if some str2ba() versions are notoriously buggy, we should probably not use it, IMHO.

    @mmaker
    Copy link
    Mannequin Author

    mmaker mannequin commented Jun 10, 2014

    ping.

    @csabella
    Copy link
    Contributor

    Michele Orrù,

    Would you be interested in making a GitHub pull request for your patch? Thanks!

    @vstinner
    Copy link
    Member

    In Modules/socketmodule.c , the bluetooth address supplied is vulnerable to integer overflow.

    Attached PR 12864 modifies the following code:

      unsigned int b0, b1, b2, b3, b4, b5;
      char ch;
      int n;
      n = sscanf(name, "%X:%X:%X:%X:%X:%X%c", &b5, &b4, &b3, &b2, &b1, &b0, &ch);

    Can someone please elaborate how this code can trigger an integer overflow? What is the consequence of an integer overflow? Does Python crash?

    @vstinner vstinner added 3.7 (EOL) end of life 3.8 only security fixes labels Apr 17, 2019
    @vstinner vstinner changed the title Integer overflow in socketmodule Integer overflow in the socket function parsing a Bluetooth address Apr 17, 2019
    @serhiy-storchaka
    Copy link
    Member

    Seconded Viktor's question.

    @zooba
    Copy link
    Member

    zooba commented Apr 22, 2019

    According to a couple of scanf docs I found, the '%x' format expects to write into unsigned int*, just as we already do. So it shouldn't be possible to overflow there.

    The following line (or-ing all the values and checking that it's less than 256) handles the overflow already.

    Limiting each %x specifier to two characters has exactly the same effect, and could potentially fix overflow errors in C runtimes that assume a larger destination without the data size prefix ('%zx' or '%llx'), but I don't know of any of those.

    All that said, I'm not opposed to adding the tests. If the parsing logic is a sticking point, then that can be undone, but I think it's also okay.

    @vstinner
    Copy link
    Member

    Hum, maybe I'm just confused by "integer overflow". To me, "integer overflow" means that an operation goes out of the bounds of a C integer type. But here, the problem is more than the parser accepts invalid Bluetooth addresses?

    Please use a better title than "Fix integer overflow in socketmodule". Maybe "Fix Bluetooth address parser"?

    @mmaker mmaker mannequin changed the title Integer overflow in the socket function parsing a Bluetooth address Fix Bluetooth address parser May 26, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @serhiy-storchaka
    Copy link
    Member

    Closing, since there is no the claimed integer overflow here, and the PR was broken since 2019.

    @serhiy-storchaka serhiy-storchaka closed this as not planned Won't fix, can't repro, duplicate, stale Feb 3, 2024
    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 extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants