Skip to content

Commit

Permalink
kerndat: check if setsockopt IPV6_FREEBIND is supported
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Tikhomirov <[email protected]>
  • Loading branch information
Snorch authored and avagin committed Apr 16, 2023
1 parent 14e8836 commit f1c8d38
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
10 changes: 10 additions & 0 deletions criu/cr-check.c
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,14 @@ static int check_openat2(void)
return 0;
}

static int check_ipv6_freebind(void)
{
if (!kdat.has_ipv6_freebind)
return -1;

return 0;
}

static int (*chk_feature)(void);

/*
Expand Down Expand Up @@ -1494,6 +1502,7 @@ int cr_check(void)
ret |= check_move_mount_set_group();
ret |= check_openat2();
ret |= check_ptrace_get_rseq_conf();
ret |= check_ipv6_freebind();

if (kdat.lsm == LSMTYPE__APPARMOR)
ret |= check_apparmor_stacking();
Expand Down Expand Up @@ -1614,6 +1623,7 @@ static struct feature_list feature_list[] = {
{ "move_mount_set_group", check_move_mount_set_group },
{ "openat2", check_openat2 },
{ "get_rseq_conf", check_ptrace_get_rseq_conf },
{ "ipv6_freebind", check_ipv6_freebind },
{ NULL, NULL },
};

Expand Down
1 change: 1 addition & 0 deletions criu/include/kerndat.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ struct kerndat_s {
bool has_rseq;
bool has_ptrace_get_rseq_conf;
struct __ptrace_rseq_configuration libc_rseq_conf;
bool has_ipv6_freebind;
};

extern struct kerndat_s kdat;
Expand Down
32 changes: 32 additions & 0 deletions criu/kerndat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,34 @@ static int kerndat_has_nftables_concat(void)
#endif
}

#ifndef IPV6_FREEBIND
#define IPV6_FREEBIND 78
#endif

static int kerndat_has_ipv6_freebind(void)
{
int sk, val;

sk = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
if (sk == -1) {
pr_perror("Unable to create a ipv6 dgram socket");
return -1;
}

val = 1;
if (setsockopt(sk, SOL_IPV6, IPV6_FREEBIND, &val, sizeof(int)) == -1) {
if (errno == ENOPROTOOPT) {
kdat.has_ipv6_freebind = false;
return 0;
}
pr_perror("Unable to setsockopt ipv6_freebind");
return -1;
}

kdat.has_ipv6_freebind = true;
return 0;
}

/*
* Some features depend on resource that can be dynamically changed
* at the OS runtime. There are cases that we cannot determine the
Expand Down Expand Up @@ -1780,6 +1808,10 @@ int kerndat_init(void)
pr_err("kerndat_has_ptrace_get_rseq_conf failed when initializing kerndat.\n");
ret = -1;
}
if (!ret && (kerndat_has_ipv6_freebind() < 0)) {
pr_err("kerndat_has_ipv6_freebind failed when initializing kerndat.\n");
ret = -1;
}

kerndat_lsm();
kerndat_mmap_min_addr();
Expand Down

0 comments on commit f1c8d38

Please sign in to comment.