linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Colin Ian King <colin.king@canonical.com>
To: Marcel Holtmann <marcel@holtmann.org>,
	Johan Hedberg <johan.hedberg@gmail.com>,
	Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: net/bluetooth/cmtp/core.c: potential buffer overrun in session->name
Date: Wed, 4 Aug 2021 10:08:18 +0100	[thread overview]
Message-ID: <2cfa6b86-da6a-207f-ec1a-e180e6275896@canonical.com> (raw)

Hi,

Static analysis with Coverity has detected a potential buffer overrun
with a sprintf into session->name in function cmtp_add_connection in
net/bluetooth/cmtp/core.c

The analysis is as follows:

Out-of-bounds write (OVERRUN)
sprintf_overrun: sprintf will overrun its first argument session->name
which can accommodate 18 bytes. The number of bytes written may be 21
bytes, including the terminating null.

363        sprintf(session->name, "%pMR", &session->bdaddr);

So, %pMR produces can potentially produce 0x............MR\0 (where . is
a hex digit) so this accounts for 21 chars. session->name is defined as:

char name[BTNAMSIZ];

and BTNAMSIZE is:

#define BTNAMSIZ 18

Although an obvious fix is to increase BTNAMSIZE to 21 I'm not sure if
this is actually the correct fix.

Colin

             reply	other threads:[~2021-08-04  9:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-04  9:08 Colin Ian King [this message]
2021-08-04 14:46 ` net/bluetooth/cmtp/core.c: potential buffer overrun in session->name Marcel Holtmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2cfa6b86-da6a-207f-ec1a-e180e6275896@canonical.com \
    --to=colin.king@canonical.com \
    --cc=johan.hedberg@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).