Skip to content

Commit

Permalink
Revert 21b97b1
Browse files Browse the repository at this point in the history
Bug #247 is not bound to show up again.
  • Loading branch information
ydahhrk committed Mar 20, 2022
1 parent 344b058 commit 4af409c
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 132 deletions.
5 changes: 0 additions & 5 deletions src/mod/common/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ verdict core_4to6(struct sk_buff *skb, struct xlation *state)

if (state->jool.globals.debug)
pkt_trace4(state);
/* skb_log(skb, "Incoming IPv4 packet"); */

result = core_common(state);
/* Fall through */
Expand Down Expand Up @@ -145,8 +144,6 @@ verdict core_6to4(struct sk_buff *skb, struct xlation *state)
* pkt_init_ipv6() HAS pskb_may_pull()ED THEM.
*/

snapshot_record(&state->in.debug.shot1, skb);

result = validate_xlator(state);
if (result != VERDICT_CONTINUE)
goto end;
Expand All @@ -160,8 +157,6 @@ verdict core_6to4(struct sk_buff *skb, struct xlation *state)

if (state->jool.globals.debug)
pkt_trace6(state);
/* skb_log(skb, "Incoming IPv6 packet"); */
snapshot_record(&state->in.debug.shot2, skb);

result = core_common(state);
/* Fall through */
Expand Down
62 changes: 0 additions & 62 deletions src/mod/common/packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,65 +575,3 @@ unsigned char *jskb_pull(struct sk_buff *skb, unsigned int len)
len, skb->len);
return result;
}

#define SIMPLE_MIN(a, b) ((a < b) ? a : b)

void snapshot_record(struct pkt_snapshot *shot, struct sk_buff *skb)
{
struct skb_shared_info *shinfo = skb_shinfo(skb);
unsigned int limit;
unsigned int i;

shot->len = skb->len;
shot->data_len = skb->data_len;
shot->nr_frags = shinfo->nr_frags;

limit = SIMPLE_MIN(SNAPSHOT_FRAGS_SIZE, shot->nr_frags);
for (i = 0; i < limit; i++)
shot->frags[i] = skb_frag_size(&shinfo->frags[i]);

/*
* Ok so I only have room for SNAPSHOT_FRAGS_SIZE page sizes, unless I
* allocate. I don't want to allocate because that's an additional fail
* opportunity and I want this to be as unintrusive as possible.
*
* First of all, since PAGE_SIZE is 4k in my VM, and the typical
* Internet MTU is 1500 max, I don't think the packet is going
* to have more than one page.
*
* (Unless IP fragments are being treated as pages, but I don't think
* that's the case here because the crashing packet was an ICMP error,
* and defrag discards fragmented ICMP errors on reception because they
* are BS.)
*
* Second, even if we get multiple pages, I don't see why would they
* have different sizes. Except for the last one, that is.
*
* (Unless the crashing pages were IP fragments. Again, I don't think
* this is the case.)
*
* Therefore, if the packet has more than SNAPSHOT_FRAGS_SIZE pages,
* I'm going to risk it and override the last slottable page size with
* the most interesting one. (The last one.)
*
* Consider that when you're reading the output.
*/
if (shot->nr_frags > SNAPSHOT_FRAGS_SIZE) {
shot->frags[SNAPSHOT_FRAGS_SIZE - 1]
= skb_frag_size(&shinfo->frags[shot->nr_frags - 1]);
}
}

void snapshot_report(struct pkt_snapshot *shot, char *prefix)
{
unsigned int limit;
unsigned int i;

pr_err("%s len: %u\n", prefix, shot->len);
pr_err("%s data_len: %u\n", prefix, shot->data_len);
pr_err("%s nr_frags: %u\n", prefix, shot->nr_frags);

limit = SIMPLE_MIN(SNAPSHOT_FRAGS_SIZE, shot->nr_frags);
for (i = 0; i < limit; i++)
pr_err(" %s frag %u: %u\n", prefix, i, shot->frags[i]);
}
17 changes: 0 additions & 17 deletions src/mod/common/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,6 @@ static inline unsigned int tcp_hdr_len(const struct tcphdr *hdr)
return hdr->doff << 2;
}

#define SNAPSHOT_FRAGS_SIZE 5

struct pkt_snapshot {
unsigned int len;
unsigned int data_len;
unsigned char nr_frags;
unsigned int frags[SNAPSHOT_FRAGS_SIZE];
};

/**
* We need to store packet metadata, so we encapsulate sk_buffs into this.
*
Expand Down Expand Up @@ -245,11 +236,6 @@ struct packet {
* packet.
*/
struct packet *original_pkt;

struct {
struct pkt_snapshot shot1;
struct pkt_snapshot shot2;
} debug;
};

/**
Expand Down Expand Up @@ -450,7 +436,4 @@ verdict pkt_init_ipv4(struct xlation *state, struct sk_buff *skb);
unsigned char *jskb_pull(struct sk_buff *skb, unsigned int len);
unsigned char *jskb_push(struct sk_buff *skb, unsigned int len);

void snapshot_record(struct pkt_snapshot *shot, struct sk_buff *skb);
void snapshot_report(struct pkt_snapshot *shot, char *prefix);

#endif /* SRC_MOD_COMMON_PACKET_H_ */
48 changes: 0 additions & 48 deletions src/mod/common/rfc7915/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,59 +26,11 @@ bool will_need_frag_hdr(const struct iphdr *hdr)
return is_fragmented_ipv4(hdr);
}

static int report_bug247(struct packet *pkt, __u8 proto)
{
struct sk_buff *skb = pkt->skb;
struct skb_shared_info *shinfo = skb_shinfo(skb);
unsigned int i;
unsigned char *pos;

pr_err("----- JOOL OUTPUT -----\n");
pr_err("Bug #247 happened!\n");

pr_err("xlator: " JOOL_VERSION_STR);
pr_err("Page size: %lu\n", PAGE_SIZE);
pr_err("Page shift: %u\n", PAGE_SHIFT);
pr_err("protocols: %u %u %u\n", pkt->l3_proto, pkt->l4_proto, proto);

snapshot_report(&pkt->debug.shot1, "initial");
snapshot_report(&pkt->debug.shot2, "mid");

pr_err("current len: %u\n", skb->len);
pr_err("current data_len: %u\n", skb->data_len);
pr_err("current nr_frags: %u\n", shinfo->nr_frags);
for (i = 0; i < shinfo->nr_frags; i++) {
pr_err(" current frag %u: %u\n", i,
skb_frag_size(&shinfo->frags[i]));
}

pr_err("skb head:%p data:%p tail:%p end:%p\n",
skb->head, skb->data,
skb_tail_pointer(skb),
skb_end_pointer(skb));
pr_err("skb l3-hdr:%p l4-hdr:%p payload:%p\n",
skb_network_header(skb),
skb_transport_header(skb),
pkt_payload(pkt));

pr_err("packet content: ");
for (pos = skb->head; pos < skb_end_pointer(skb); pos++)
pr_cont("%x ", *pos);
pr_cont("\n");

pr_err("Dropping packet.\n");
pr_err("-----------------------\n");
return -EINVAL;
}

static int move_pointers_in(struct packet *pkt, __u8 protocol,
unsigned int l3hdr_len)
{
unsigned int l4hdr_len;

if (unlikely(pkt->skb->len - pkt_hdrs_len(pkt) < pkt->skb->data_len))
return report_bug247(pkt, protocol);

if (!jskb_pull(pkt->skb, pkt_hdrs_len(pkt)))
return -EINVAL;
skb_reset_network_header(pkt->skb);
Expand Down

0 comments on commit 4af409c

Please sign in to comment.