Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

add missing memory allocation checks #199

Merged
merged 28 commits into from
Apr 3, 2024
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
41d07fa
augmentation ENOMEM handling
waynz0r Mar 30, 2024
1c3d8df
sd ENOMEM handling
waynz0r Mar 30, 2024
958ac0a
buffer and camblet new socket ENOMEM handling
waynz0r Mar 31, 2024
37fffd7
cert tools ENOMEM handling
waynz0r Mar 31, 2024
804c72d
commands ENOMEM handling
waynz0r Mar 31, 2024
4b10670
config ENOMEM handling
waynz0r Mar 31, 2024
cfb97a8
csr ENOMEM handling
waynz0r Mar 31, 2024
f1f1f3e
refactor main.c for better error handling
waynz0r Mar 31, 2024
b77a4e8
fix cert tools
waynz0r Mar 31, 2024
67fa8a9
device driver ENOMEM handling
waynz0r Apr 1, 2024
8441691
opa ENOMEM handling
waynz0r Apr 1, 2024
d05fa78
fix init csr error handling
waynz0r Apr 1, 2024
0112b95
rsa tools ENOMEM handling
waynz0r Apr 1, 2024
691e2f5
socket ENOMEM handling
waynz0r Apr 1, 2024
ab6b86d
task context ENOMEM handling
waynz0r Apr 1, 2024
b5e72d1
tls ENOMEM handling
waynz0r Apr 1, 2024
c3e99ea
fix missing opa socket context free
waynz0r Apr 1, 2024
0a60de4
favor kstr(n)dup over our implementation
waynz0r Apr 1, 2024
3fc020e
use ERR_PTR in strprintf
waynz0r Apr 1, 2024
bb1ff48
wasm handle ENOMEM
waynz0r Apr 1, 2024
fcd2dae
update bearssl
waynz0r Apr 1, 2024
e2efa74
fix hash reset and printfs
waynz0r Apr 1, 2024
bc019db
fix augmentation cache key freeing
waynz0r Apr 2, 2024
8fc294a
use IS_ERR_OR_NULL
waynz0r Apr 3, 2024
2711d67
camblet_(accept|connect): return early on downstream func error
waynz0r Apr 3, 2024
7aaadd2
remove unnecessary local variable
waynz0r Apr 3, 2024
a0e761e
fix potential race condition
waynz0r Apr 3, 2024
39e9021
fix freeiing
waynz0r Apr 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,8 @@ int camblet_setsockopt(struct sock *sk, int level,
}

s->hostname = kzalloc(optlen, GFP_KERNEL);
if (!s->hostname)
return -ENOMEM;
copy_from_sockptr(s->hostname, optval, optlen);
return 0;
}
Expand Down Expand Up @@ -1343,7 +1345,12 @@ static int handle_cert_gen_locked(camblet_socket *sc)
return -1;
}

csr_ptr = strndup(generated_csr.csr_ptr + mem, generated_csr.csr_len);
csr_ptr = kstrndup(generated_csr.csr_ptr + mem, generated_csr.csr_len, GFP_KERNEL);
if (!csr_ptr)
{
csr_unlock(csr);
return -ENOMEM;
}
free_result = csr_free(csr, generated_csr.csr_ptr);
if (free_result.err)
{
Expand Down Expand Up @@ -1425,6 +1432,8 @@ static int cache_and_validate_cert(camblet_socket *sc, char *key)
static tcp_connection_context *tcp_connection_context_init(direction direction, struct sock *s, u16 port)
{
tcp_connection_context *ctx = kzalloc(sizeof(tcp_connection_context), GFP_KERNEL);
if (!ctx)
return ERR_PTR(-ENOMEM);

ctx->direction = direction;
ctx->id = (u64)s;
Expand Down Expand Up @@ -1481,7 +1490,7 @@ static tcp_connection_context *tcp_connection_context_init(direction direction,

static void tcp_connection_context_free(tcp_connection_context *ctx)
{
if (!ctx)
if (!ctx && IS_ERR(ctx))
waynz0r marked this conversation as resolved.
Show resolved Hide resolved
{
return;
}
Expand Down Expand Up @@ -1581,6 +1590,11 @@ static command_answer *prepare_opa_input(const tcp_connection_context *conn_ctx,
}

answer = kzalloc(sizeof(struct command_answer), GFP_KERNEL);
if (!answer)
{
json_value_free(json);
return ERR_PTR(-ENOMEM);
}
answer->answer = json_serialize_to_string(json);

cleanup:
Expand Down Expand Up @@ -1844,6 +1858,11 @@ struct sock *camblet_accept(struct sock *sk, int flags, int *err, bool kern)
u16 port = (u16)(sk->sk_portpair >> 16);

tcp_connection_context *conn_ctx = tcp_connection_context_init(INPUT, client_sk, port);
if (IS_ERR(conn_ctx))
{
*err = PTR_ERR(conn_ctx);
goto error;
}

opa_socket_context opa_socket_ctx = enriched_socket_eval(conn_ctx, INPUT, client_sk, port);
if (opa_socket_ctx.error < 0)
Expand Down Expand Up @@ -1934,6 +1953,11 @@ int camblet_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
}

tcp_connection_context *conn_ctx = tcp_connection_context_init(OUTPUT, sk, port);
if (IS_ERR(conn_ctx))
{
err = PTR_ERR(conn_ctx);
goto error;
}

opa_socket_context opa_socket_ctx = enriched_socket_eval(conn_ctx, OUTPUT, sk, port);
if (opa_socket_ctx.error < 0)
Expand Down