Re: [PATCH v1] hog: Check security level before setting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Luiz,

On 2024/11/18 23:13, Luiz Augusto von Dentz wrote:
Hi Jiayang,

On Mon, Nov 18, 2024 at 4:49 AM Jiayang Mao <quic_jiaymao@xxxxxxxxxxx> wrote:

bt_gatt_client_set_security could fail if the security level is
already BT_ATT_SECURITY_MEDIUM. So, get and check the security
level before setting it.

Seems a bit strange that this is not handled by the kernel, can you
elaborate on the conditions to trigger it?


In the kernel, the failure happens when smp_sufficient_security() in
'net/bluetooth/smp.c' returns true. In some cases, when security level
is already MEDIUM but long term key is not ready, setting security level
will fail. Checking security level before setting it can prevent this
failure.

Signed-off-by: Jiayang Mao <quic_jiaymao@xxxxxxxxxxx>
---
  profiles/input/hog.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/profiles/input/hog.c b/profiles/input/hog.c
index 017e320f0..011cc0a88 100644
--- a/profiles/input/hog.c
+++ b/profiles/input/hog.c
@@ -191,8 +191,10 @@ static int hog_accept(struct btd_service *service)
                         return -ECONNREFUSED;

                 client = btd_device_get_gatt_client(device);
-               if (!bt_gatt_client_set_security(client,
-                                               BT_ATT_SECURITY_MEDIUM))
+               if (BT_ATT_SECURITY_MEDIUM !=
+                       bt_gatt_client_get_security(client) &&
+                   !bt_gatt_client_set_security(client,
+                                                BT_ATT_SECURITY_MEDIUM))
                         return -ECONNREFUSED;


Definitely not the right way to fix this since there might be other
places that do attempt to set the security, so Id got with something
like the following:

diff --git a/src/shared/att.c b/src/shared/att.c
index 4a406f4b91a4..dabbdb4315eb 100644
--- a/src/shared/att.c
+++ b/src/shared/att.c
@@ -727,6 +727,9 @@ static bool bt_att_chan_set_security(struct
bt_att_chan *chan, int level)
  {
         struct bt_security sec;

+       if (level == bt_att_chan_get_security(chan))
+               return true;
+
         if (chan->type == BT_ATT_LOCAL) {
                 chan->sec_level = level;
                 return true;

         }

--
2.25.1









[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux