/* let's make sure that 16 bytes of payload are in the linear part of skb */
bpf_skb_pull_data(skb, offset + 16);
bpf_dynptr_from_skb(skb, 0, psrc);
bpf_dynptr_adjust(psrc, offset, offset + 16);
cctx = bpf_crypto_ctx_create(¶ms, sizeof(params), &err); if (!cctx) {
status = err; return 0;
}
err = crypto_ctx_insert(cctx); if (err && err != -EEXIST)
status = err; return 0;
}
SEC("tc") int decrypt_sanity(struct __sk_buff *skb)
{ struct __crypto_ctx_value *v; struct bpf_crypto_ctx *ctx; struct bpf_dynptr psrc, pdst; int err;
status = 0;
err = skb_dynptr_validate(skb, &psrc); if (err < 0) {
status = err; return TC_ACT_SHOT;
}
v = crypto_ctx_value_lookup(); if (!v) {
status = -ENOENT; return TC_ACT_SHOT;
}
ctx = v->ctx; if (!ctx) {
status = -ENOENT; return TC_ACT_SHOT;
}
/* Check also bad case where the dst buffer is smaller than the * skb's linear section.
*/
bpf_dynptr_from_mem(dst_bad, sizeof(dst_bad), 0, &pdst);
status = bpf_crypto_decrypt(ctx, &psrc, &pdst, NULL); if (!status)
status = -EIO; if (status != -EINVAL) goto err;
/* dst is a global variable to make testing part easier to check. * In real production code, a percpu map should be used to store * the result.
*/
bpf_dynptr_from_mem(dst, sizeof(dst), 0, &pdst);
status = bpf_crypto_decrypt(ctx, &psrc, &pdst, NULL);
err: return TC_ACT_SHOT;
}
SEC("tc") int encrypt_sanity(struct __sk_buff *skb)
{ struct __crypto_ctx_value *v; struct bpf_crypto_ctx *ctx; struct bpf_dynptr psrc, pdst; int err;
status = 0;
err = skb_dynptr_validate(skb, &psrc); if (err < 0) {
status = err; return TC_ACT_SHOT;
}
v = crypto_ctx_value_lookup(); if (!v) {
status = -ENOENT; return TC_ACT_SHOT;
}
ctx = v->ctx; if (!ctx) {
status = -ENOENT; return TC_ACT_SHOT;
}
/* Check also bad case where the dst buffer is smaller than the * skb's linear section.
*/
bpf_dynptr_from_mem(dst_bad, sizeof(dst_bad), 0, &pdst);
status = bpf_crypto_encrypt(ctx, &psrc, &pdst, NULL); if (!status)
status = -EIO; if (status != -EINVAL) goto err;
/* dst is a global variable to make testing part easier to check. * In real production code, a percpu map should be used to store * the result.
*/
bpf_dynptr_from_mem(dst, sizeof(dst), 0, &pdst);
status = bpf_crypto_encrypt(ctx, &psrc, &pdst, NULL);
err: return TC_ACT_SHOT;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.