Skip to content

Commit 6811744

Browse files
phi-nguyendpgregkh
authored andcommitted
netrom: Decrease sock refcount when sock timers expire
[ Upstream commit 517a16b ] Commit 6334665 ("netrom: switch to sock timer API") switched to use sock timer API. It replaces mod_timer() by sk_reset_timer(), and del_timer() by sk_stop_timer(). Function sk_reset_timer() will increase the refcount of sock if it is called on an inactive timer, hence, in case the timer expires, we need to decrease the refcount ourselves in the handler, otherwise, the sock refcount will be unbalanced and the sock will never be freed. Signed-off-by: Nguyen Dinh Phi <phind.uet@gmail.com> Reported-by: syzbot+10f1194569953b72f1ae@syzkaller.appspotmail.com Fixes: 6334665 ("netrom: switch to sock timer API") Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 096a8dc commit 6811744

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

‎net/netrom/nr_timer.c‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,9 @@ static void nr_heartbeat_expiry(struct timer_list *t)
121121
is accepted() it isn't 'dead' so doesn't get removed. */
122122
if (sock_flag(sk, SOCK_DESTROY) ||
123123
(sk->sk_state == TCP_LISTEN && sock_flag(sk, SOCK_DEAD))) {
124-
sock_hold(sk);
125124
bh_unlock_sock(sk);
126125
nr_destroy_socket(sk);
127-
sock_put(sk);
128-
return;
126+
goto out;
129127
}
130128
break;
131129

@@ -146,6 +144,8 @@ static void nr_heartbeat_expiry(struct timer_list *t)
146144

147145
nr_start_heartbeat(sk);
148146
bh_unlock_sock(sk);
147+
out:
148+
sock_put(sk);
149149
}
150150

151151
static void nr_t2timer_expiry(struct timer_list *t)
@@ -159,6 +159,7 @@ static void nr_t2timer_expiry(struct timer_list *t)
159159
nr_enquiry_response(sk);
160160
}
161161
bh_unlock_sock(sk);
162+
sock_put(sk);
162163
}
163164

164165
static void nr_t4timer_expiry(struct timer_list *t)
@@ -169,6 +170,7 @@ static void nr_t4timer_expiry(struct timer_list *t)
169170
bh_lock_sock(sk);
170171
nr_sk(sk)->condition &= ~NR_COND_PEER_RX_BUSY;
171172
bh_unlock_sock(sk);
173+
sock_put(sk);
172174
}
173175

174176
static void nr_idletimer_expiry(struct timer_list *t)
@@ -197,6 +199,7 @@ static void nr_idletimer_expiry(struct timer_list *t)
197199
sock_set_flag(sk, SOCK_DEAD);
198200
}
199201
bh_unlock_sock(sk);
202+
sock_put(sk);
200203
}
201204

202205
static void nr_t1timer_expiry(struct timer_list *t)
@@ -209,8 +212,7 @@ static void nr_t1timer_expiry(struct timer_list *t)
209212
case NR_STATE_1:
210213
if (nr->n2count == nr->n2) {
211214
nr_disconnect(sk, ETIMEDOUT);
212-
bh_unlock_sock(sk);
213-
return;
215+
goto out;
214216
} else {
215217
nr->n2count++;
216218
nr_write_internal(sk, NR_CONNREQ);
@@ -220,8 +222,7 @@ static void nr_t1timer_expiry(struct timer_list *t)
220222
case NR_STATE_2:
221223
if (nr->n2count == nr->n2) {
222224
nr_disconnect(sk, ETIMEDOUT);
223-
bh_unlock_sock(sk);
224-
return;
225+
goto out;
225226
} else {
226227
nr->n2count++;
227228
nr_write_internal(sk, NR_DISCREQ);
@@ -231,8 +232,7 @@ static void nr_t1timer_expiry(struct timer_list *t)
231232
case NR_STATE_3:
232233
if (nr->n2count == nr->n2) {
233234
nr_disconnect(sk, ETIMEDOUT);
234-
bh_unlock_sock(sk);
235-
return;
235+
goto out;
236236
} else {
237237
nr->n2count++;
238238
nr_requeue_frames(sk);
@@ -241,5 +241,7 @@ static void nr_t1timer_expiry(struct timer_list *t)
241241
}
242242

243243
nr_start_t1timer(sk);
244+
out:
244245
bh_unlock_sock(sk);
246+
sock_put(sk);
245247
}

0 commit comments

Comments
 (0)