Skip to content

Commit

Permalink
bpf: Sockmap/tls, push write_space updates through ulp updates
Browse files Browse the repository at this point in the history
When sockmap sock with TLS enabled is removed we cleanup bpf/psock state
and call tcp_update_ulp() to push updates to TLS ULP on top. However, we
don't push the write_space callback up and instead simply overwrite the
op with the psock stored previous op. This may or may not be correct so
to ensure we don't overwrite the TLS write space hook pass this field to
the ULP and have it fixup the ctx.

This completes a previous fix that pushed the ops through to the ULP
but at the time missed doing this for write_space, presumably because
write_space TLS hook was added around the same time.

Fixes: 95fa145 ("bpf: sockmap/tls, close can race with map free")
Signed-off-by: John Fastabend <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Reviewed-by: Jakub Sitnicki <[email protected]>
Acked-by: Jonathan Lemon <[email protected]>
Cc: [email protected]
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
jrfastab authored and borkmann committed Jan 15, 2020
1 parent 7e81a35 commit 33bfe20
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
12 changes: 8 additions & 4 deletions include/linux/skmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,17 +359,21 @@ static inline void sk_psock_restore_proto(struct sock *sk,
struct sk_psock *psock)
{
sk->sk_prot->unhash = psock->saved_unhash;
sk->sk_write_space = psock->saved_write_space;

if (psock->sk_proto) {
struct inet_connection_sock *icsk = inet_csk(sk);
bool has_ulp = !!icsk->icsk_ulp_data;

if (has_ulp)
tcp_update_ulp(sk, psock->sk_proto);
else
if (has_ulp) {
tcp_update_ulp(sk, psock->sk_proto,
psock->saved_write_space);
} else {
sk->sk_prot = psock->sk_proto;
sk->sk_write_space = psock->saved_write_space;
}
psock->sk_proto = NULL;
} else {
sk->sk_write_space = psock->saved_write_space;
}
}

Expand Down
6 changes: 4 additions & 2 deletions include/net/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -2147,7 +2147,8 @@ struct tcp_ulp_ops {
/* initialize ulp */
int (*init)(struct sock *sk);
/* update ulp */
void (*update)(struct sock *sk, struct proto *p);
void (*update)(struct sock *sk, struct proto *p,
void (*write_space)(struct sock *sk));
/* cleanup ulp */
void (*release)(struct sock *sk);
/* diagnostic */
Expand All @@ -2162,7 +2163,8 @@ void tcp_unregister_ulp(struct tcp_ulp_ops *type);
int tcp_set_ulp(struct sock *sk, const char *name);
void tcp_get_available_ulp(char *buf, size_t len);
void tcp_cleanup_ulp(struct sock *sk);
void tcp_update_ulp(struct sock *sk, struct proto *p);
void tcp_update_ulp(struct sock *sk, struct proto *p,
void (*write_space)(struct sock *sk));

#define MODULE_ALIAS_TCP_ULP(name) \
__MODULE_INFO(alias, alias_userspace, name); \
Expand Down
6 changes: 4 additions & 2 deletions net/ipv4/tcp_ulp.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,19 @@ void tcp_get_available_ulp(char *buf, size_t maxlen)
rcu_read_unlock();
}

void tcp_update_ulp(struct sock *sk, struct proto *proto)
void tcp_update_ulp(struct sock *sk, struct proto *proto,
void (*write_space)(struct sock *sk))
{
struct inet_connection_sock *icsk = inet_csk(sk);

if (!icsk->icsk_ulp_ops) {
sk->sk_write_space = write_space;
sk->sk_prot = proto;
return;
}

if (icsk->icsk_ulp_ops->update)
icsk->icsk_ulp_ops->update(sk, proto);
icsk->icsk_ulp_ops->update(sk, proto, write_space);
}

void tcp_cleanup_ulp(struct sock *sk)
Expand Down
10 changes: 7 additions & 3 deletions net/tls/tls_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,15 +732,19 @@ static int tls_init(struct sock *sk)
return rc;
}

static void tls_update(struct sock *sk, struct proto *p)
static void tls_update(struct sock *sk, struct proto *p,
void (*write_space)(struct sock *sk))
{
struct tls_context *ctx;

ctx = tls_get_ctx(sk);
if (likely(ctx))
if (likely(ctx)) {
ctx->sk_write_space = write_space;
ctx->sk_proto = p;
else
} else {
sk->sk_prot = p;
sk->sk_write_space = write_space;
}
}

static int tls_get_info(const struct sock *sk, struct sk_buff *skb)
Expand Down

0 comments on commit 33bfe20

Please sign in to comment.