[PATCH AUTOSEL 4.4 2/3] phonet/pep: refuse to enable an unbound pipe

From: Sasha Levin
Date: Mon Dec 27 2021 - 14:08:19 EST


From: Rémi Denis-Courmont <remi@xxxxxxxxxx>

[ Upstream commit 75a2f31520095600f650597c0ac41f48b5ba0068 ]

This ioctl() implicitly assumed that the socket was already bound to
a valid local socket name, i.e. Phonet object. If the socket was not
bound, two separate problems would occur:

1) We'd send an pipe enablement request with an invalid source object.
2) Later socket calls could BUG on the socket unexpectedly being
connected yet not bound to a valid object.

Reported-by: syzbot+2dc91e7fc3dea88b1e8a@xxxxxxxxxxxxxxxxxxxxxxxxx
Signed-off-by: Rémi Denis-Courmont <remi@xxxxxxxxxx>
Signed-off-by: David S. Miller <davem@xxxxxxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
net/phonet/pep.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index f6aa532bcbf64..1e7945df39928 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -956,6 +956,8 @@ static int pep_ioctl(struct sock *sk, int cmd, unsigned long arg)
ret = -EBUSY;
else if (sk->sk_state == TCP_ESTABLISHED)
ret = -EISCONN;
+ else if (!pn->pn_sk.sobject)
+ ret = -EADDRNOTAVAIL;
else
ret = pep_sock_enable(sk, NULL, 0);
release_sock(sk);
--
2.34.1