Skip to content

Commit

Permalink
Don't buffer IPT_SO_SET_REPLACE syscalls because that doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
rocallahan committed Dec 26, 2023
1 parent 2fdc856 commit b8e921f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
7 changes: 5 additions & 2 deletions src/kernel_supplement.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,11 @@ struct rr_input_mask {

// Defined in the ip_tables header for each protocol, but always to the same,
// value, so it should be fine to set this here
#ifndef SO_SET_REPLACE
#define SO_SET_REPLACE 64
#ifndef IPT_SO_SET_REPLACE
#define IPT_SO_SET_REPLACE 64
#endif
#ifndef IPV6T_SO_SET_REPLACE
#define IPV6T_SO_SET_REPLACE 64
#endif

#ifndef HCIGETDEVLIST
Expand Down
18 changes: 18 additions & 0 deletions src/preload/syscallbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ struct btrfs_ioctl_clone_range_args {
#define GRND_NONBLOCK 1
#endif

#ifndef SOL_IP
#define SOL_IP 0
#endif
#ifndef SOL_IPV6
#define SOL_IPV6 41
#endif
#ifndef IPT_SO_SET_REPLACE
#define IPT_SO_SET_REPLACE 64
#endif
#ifndef IPV6T_SO_SET_REPLACE
#define IPV6T_SO_SET_REPLACE 64
#endif

struct rr_rseq {
uint32_t cpu_id_start;
uint32_t cpu_id;
Expand Down Expand Up @@ -3395,6 +3408,11 @@ static long sys_setsockopt(struct syscall_info* call) {
// Let rr intercept this (and probably disable it)
return traced_raw_syscall(call);
}
if ((level == SOL_IP && optname == IPT_SO_SET_REPLACE) ||
(level == SOL_IPV6 && optname == IPV6T_SO_SET_REPLACE)) {
// Let rr intercept this because it has output parameters :-(
return traced_raw_syscall(call);
}

void* ptr = prep_syscall_for_fd(sockfd);
long ret;
Expand Down
34 changes: 12 additions & 22 deletions src/record_syscall.cc
Original file line number Diff line number Diff line change
Expand Up @@ -976,28 +976,18 @@ static Switchable prepare_setsockopt(RecordTask* t,
r.set_arg1(-1);
t->set_regs(r);
} else {
switch (args.level) {
case SOL_IP:
case SOL_IPV6:
switch (args.optname) {
case SO_SET_REPLACE: {
if (args.optlen < (ssize_t)sizeof(typename Arch::ipt_replace)) {
break;
}
auto repl_ptr =
args.optval.rptr().template cast<typename Arch::ipt_replace>();
syscall_state.mem_ptr_parameter(
REMOTE_PTR_FIELD(repl_ptr, counters),
t->read_mem(REMOTE_PTR_FIELD(repl_ptr, num_counters)) *
sizeof(typename Arch::xt_counters));
break;
}
default:
break;
}
break;
default:
break;
if (args.level == SOL_IP && args.optname == IPT_SO_SET_REPLACE) {
if (args.optlen < (ssize_t)sizeof(typename Arch::ipt_replace)) {
return PREVENT_SWITCH;
}
auto repl_ptr =
args.optval.rptr().template cast<typename Arch::ipt_replace>();
syscall_state.mem_ptr_parameter(
REMOTE_PTR_FIELD(repl_ptr, counters),
t->read_mem(REMOTE_PTR_FIELD(repl_ptr, num_counters)) *
sizeof(typename Arch::xt_counters));
} else if (args.level == SOL_IPV6 && args.optname == IPV6T_SO_SET_REPLACE) {
FATAL() << "IPV6T_SO_SET_REPLACE not supported yet";
}
}
return PREVENT_SWITCH;
Expand Down

0 comments on commit b8e921f

Please sign in to comment.