Skip to content

Commit af0d3b1

Browse files
hidavedavem330
authored andcommitted
bluetooth: rfcomm_init bug fix
rfcomm tty may be used before rfcomm_tty_driver initilized, The problem is that now socket layer init before tty layer, if userspace program do socket callback right here then oops will happen. reporting in: http://marc.info/?l=linux-bluetooth&m=124404919324542&w=2 make 3 changes: 1. remove #ifdef in rfcomm/core.c, make it blank function when rfcomm tty not selected in rfcomm.h 2. tune the rfcomm_init error patch to ensure tty driver initilized before rfcomm socket usage. 3. remove __exit for rfcomm_cleanup_sockets because above change need call it in a __init function. Reported-by: Oliver Hartkopp <oliver@hartkopp.net> Tested-by: Oliver Hartkopp <oliver@hartkopp.net> Signed-off-by: Dave Young <hidave.darkstar@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent eb4ad82 commit af0d3b1

3 files changed

Lines changed: 31 additions & 10 deletions

File tree

‎include/net/bluetooth/rfcomm.h‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,17 @@ struct rfcomm_dev_list_req {
355355
};
356356

357357
int rfcomm_dev_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
358+
359+
#ifdef CONFIG_BT_RFCOMM_TTY
358360
int rfcomm_init_ttys(void);
359361
void rfcomm_cleanup_ttys(void);
360-
362+
#else
363+
static inline int rfcomm_init_ttys(void)
364+
{
365+
return 0;
366+
}
367+
static inline void rfcomm_cleanup_ttys(void)
368+
{
369+
}
370+
#endif
361371
#endif /* __RFCOMM_H */

‎net/bluetooth/rfcomm/core.c‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,28 +2080,41 @@ static CLASS_ATTR(rfcomm_dlc, S_IRUGO, rfcomm_dlc_sysfs_show, NULL);
20802080
/* ---- Initialization ---- */
20812081
static int __init rfcomm_init(void)
20822082
{
2083+
int ret;
2084+
20832085
l2cap_load();
20842086

20852087
hci_register_cb(&rfcomm_cb);
20862088

20872089
rfcomm_thread = kthread_run(rfcomm_run, NULL, "krfcommd");
20882090
if (IS_ERR(rfcomm_thread)) {
2089-
hci_unregister_cb(&rfcomm_cb);
2090-
return PTR_ERR(rfcomm_thread);
2091+
ret = PTR_ERR(rfcomm_thread);
2092+
goto out_thread;
20912093
}
20922094

20932095
if (class_create_file(bt_class, &class_attr_rfcomm_dlc) < 0)
20942096
BT_ERR("Failed to create RFCOMM info file");
20952097

2096-
rfcomm_init_sockets();
2098+
ret = rfcomm_init_ttys();
2099+
if (ret)
2100+
goto out_tty;
20972101

2098-
#ifdef CONFIG_BT_RFCOMM_TTY
2099-
rfcomm_init_ttys();
2100-
#endif
2102+
ret = rfcomm_init_sockets();
2103+
if (ret)
2104+
goto out_sock;
21012105

21022106
BT_INFO("RFCOMM ver %s", VERSION);
21032107

21042108
return 0;
2109+
2110+
out_sock:
2111+
rfcomm_cleanup_ttys();
2112+
out_tty:
2113+
kthread_stop(rfcomm_thread);
2114+
out_thread:
2115+
hci_unregister_cb(&rfcomm_cb);
2116+
2117+
return ret;
21052118
}
21062119

21072120
static void __exit rfcomm_exit(void)
@@ -2112,9 +2125,7 @@ static void __exit rfcomm_exit(void)
21122125

21132126
kthread_stop(rfcomm_thread);
21142127

2115-
#ifdef CONFIG_BT_RFCOMM_TTY
21162128
rfcomm_cleanup_ttys();
2117-
#endif
21182129

21192130
rfcomm_cleanup_sockets();
21202131
}

‎net/bluetooth/rfcomm/sock.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ int __init rfcomm_init_sockets(void)
11321132
return err;
11331133
}
11341134

1135-
void __exit rfcomm_cleanup_sockets(void)
1135+
void rfcomm_cleanup_sockets(void)
11361136
{
11371137
class_remove_file(bt_class, &class_attr_rfcomm);
11381138

0 commit comments

Comments
 (0)