Skip to content

Commit

Permalink
sctp: sctp_sock_filter(): avoid list_entry() on possibly empty list
Browse files Browse the repository at this point in the history
Use list_is_first() to check whether tsp->asoc matches the first
element of ep->asocs, as the list is not guaranteed to have an entry.

Fixes: 8f840e4 ("sctp: add the sctp_diag.c file")
Signed-off-by: Pietro Borrello <borrello@diag.uniroma1.it>
Acked-by: Xin Long <lucien.xin@gmail.com>
Link: https://lore.kernel.org/r/20230208-sctp-filter-v2-1-6e1f4017f326@diag.uniroma1.it
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Pietro Borrello authored and Jakub Kicinski committed Feb 11, 2023
1 parent 0ed577e commit a122170
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions net/sctp/diag.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,9 @@ static int sctp_sock_filter(struct sctp_endpoint *ep, struct sctp_transport *tsp
struct sctp_comm_param *commp = p;
struct sock *sk = ep->base.sk;
const struct inet_diag_req_v2 *r = commp->r;
struct sctp_association *assoc =
list_entry(ep->asocs.next, struct sctp_association, asocs);

/* find the ep only once through the transports by this condition */
if (tsp->asoc != assoc)
if (!list_is_first(&tsp->asoc->asocs, &ep->asocs))
return 0;

if (r->sdiag_family != AF_UNSPEC && sk->sk_family != r->sdiag_family)
Expand Down

0 comments on commit a122170

Please sign in to comment.