Skip to content

Commit

Permalink
Bluetooth: Restrict application of socket options
Browse files Browse the repository at this point in the history
The new socket options should only be evaluated for SOL_BLUETOOTH level
and not for every other level. Previously this causes some minor issues
when detecting if a kernel with certain features is available.

Also restrict BT_SECURITY to SOCK_SEQPACKET for L2CAP and SOCK_STREAM for
the RFCOMM protocol.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
  • Loading branch information
Marcel Holtmann committed Feb 27, 2009
1 parent f62e432 commit 0588d94
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions net/bluetooth/l2cap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1248,10 +1248,18 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
if (level == SOL_L2CAP)
return l2cap_sock_setsockopt_old(sock, optname, optval, optlen);

if (level != SOL_BLUETOOTH)
return -ENOPROTOOPT;

lock_sock(sk);

switch (optname) {
case BT_SECURITY:
if (sk->sk_type != SOCK_SEQPACKET) {
err = -EINVAL;
break;
}

sec.level = BT_SECURITY_LOW;

len = min_t(unsigned int, sizeof(sec), optlen);
Expand Down Expand Up @@ -1384,13 +1392,21 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, ch
if (level == SOL_L2CAP)
return l2cap_sock_getsockopt_old(sock, optname, optval, optlen);

if (level != SOL_BLUETOOTH)
return -ENOPROTOOPT;

if (get_user(len, optlen))
return -EFAULT;

lock_sock(sk);

switch (optname) {
case BT_SECURITY:
if (sk->sk_type != SOCK_SEQPACKET) {
err = -EINVAL;
break;
}

sec.level = l2cap_pi(sk)->sec_level;

len = min_t(unsigned int, len, sizeof(sec));
Expand Down
16 changes: 16 additions & 0 deletions net/bluetooth/rfcomm/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,10 +778,18 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
if (level == SOL_RFCOMM)
return rfcomm_sock_setsockopt_old(sock, optname, optval, optlen);

if (level != SOL_BLUETOOTH)
return -ENOPROTOOPT;

lock_sock(sk);

switch (optname) {
case BT_SECURITY:
if (sk->sk_type != SOCK_STREAM) {
err = -EINVAL;
break;
}

sec.level = BT_SECURITY_LOW;

len = min_t(unsigned int, sizeof(sec), optlen);
Expand Down Expand Up @@ -899,13 +907,21 @@ static int rfcomm_sock_getsockopt(struct socket *sock, int level, int optname, c
if (level == SOL_RFCOMM)
return rfcomm_sock_getsockopt_old(sock, optname, optval, optlen);

if (level != SOL_BLUETOOTH)
return -ENOPROTOOPT;

if (get_user(len, optlen))
return -EFAULT;

lock_sock(sk);

switch (optname) {
case BT_SECURITY:
if (sk->sk_type != SOCK_STREAM) {
err = -EINVAL;
break;
}

sec.level = rfcomm_pi(sk)->sec_level;

len = min_t(unsigned int, len, sizeof(sec));
Expand Down

0 comments on commit 0588d94

Please sign in to comment.