linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Gui-Dong Han' <2045gemini@gmail.com>,
	"marcel@holtmann.org" <marcel@holtmann.org>,
	"johan.hedberg@gmail.com" <johan.hedberg@gmail.com>,
	"luiz.dentz@gmail.com" <luiz.dentz@gmail.com>
Cc: "linux-bluetooth@vger.kernel.org"
	<linux-bluetooth@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"baijiaju1990@outlook.com" <baijiaju1990@outlook.com>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>,
	BassCheck <bass@buaa.edu.cn>
Subject: RE: [PATCH] Bluetooth: Fix atomicity violation in {conn,adv}_{min,max}_interval_set
Date: Fri, 22 Dec 2023 11:41:09 +0000	[thread overview]
Message-ID: <0565eabbd25141fab9f3206db4e86196@AcuMS.aculab.com> (raw)
In-Reply-To: <20231222105526.9208-1-2045gemini@gmail.com>

From: Gui-Dong Han
> Sent: 22 December 2023 10:55
> 
> In {conn,adv}_min_interval_set():
> 	if (val < ... || val > ... || val > hdev->le_{conn,adv}_max_interval)
> 		return -EINVAL;
> 	hci_dev_lock(hdev);
> 	hdev->le_{conn,adv}_min_interval = val;
> 	hci_dev_unlock(hdev);
> 
> In {conn,adv}_max_interval_set():
> 	if (val < ... || val > ... || val < hdev->le_{conn,adv}_min_interval)
> 		return -EINVAL;
> 	hci_dev_lock(hdev);
> 	hdev->le_{conn,adv}_max_interval
> 	hci_dev_unlock(hdev);
> 
> The atomicity violation occurs due to concurrent execution of set_min and
> set_max funcs which may lead to inconsistent reads and writes of the min
> value and the max value. The checks for value validity are ineffective as
> the min/max values could change immediately after being checked, raising
> the risk of the min value being greater than the max value and causing
> invalid settings.
> 
> This possible bug is found by an experimental static analysis tool
> developed by our team, BassCheck[1]. This tool analyzes the locking APIs
> to extract function pairs that can be concurrently executed, and then
> analyzes the instructions in the paired functions to identify possible
> concurrency bugs including data races and atomicity violations. The above
> possible bug is reported when our tool analyzes the source code of
> Linux 5.17.

Your static analysis tool is basically broken.

The only possible issues are if the accesses aren't atomic.
In practise they always will be but using READ_ONCE() and
WRITE_ONCE() would make that certain.

The lock sequence:
> 	hci_dev_lock(hdev);
>  	hdev->le_conn_min_interval = val;
>  	hci_dev_unlock(hdev);
is pretty pointless - is doesn't 'lock' two+ things together.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


  parent reply	other threads:[~2023-12-22 11:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-22 10:55 [PATCH] Bluetooth: Fix atomicity violation in {conn,adv}_{min,max}_interval_set Gui-Dong Han
2023-12-22 11:31 ` bluez.test.bot
2023-12-22 11:41 ` David Laight [this message]
2023-12-22 12:03   ` [PATCH] " Gui-Dong Han

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=0565eabbd25141fab9f3206db4e86196@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=2045gemini@gmail.com \
    --cc=baijiaju1990@outlook.com \
    --cc=bass@buaa.edu.cn \
    --cc=johan.hedberg@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    --cc=stable@vger.kernel.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).