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

sockets: fix incorrect malloc size #1220

Merged
merged 2 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion criu/sockets.c
Expand Up @@ -414,12 +414,15 @@ static int restore_socket_filter(int sk, SkOptsEntry *soe)

pr_info("Restoring socket filter\n");
sfp.len = soe->n_so_filter;
sfp.filter = xmalloc(soe->n_so_filter * sfp.len);
sfp.filter = xmalloc(sfp.len * sizeof(struct sock_filter));
if (!sfp.filter)
return -1;

decode_filter(soe->so_filter, sfp.filter, sfp.len);
ret = restore_opt(sk, SOL_SOCKET, SO_ATTACH_FILTER, &sfp);
if (ret)
pr_err("Can't restore filter\n");

xfree(sfp.filter);

return ret;
Expand Down
4 changes: 3 additions & 1 deletion test/zdtm/static/Makefile
Expand Up @@ -44,7 +44,8 @@ TST_NOFILE := \
packet_sock \
packet_sock_mmap \
packet_sock_spkt \
sock_filter \
sock_filter00 \
sock_filter01 \
msgque \
inotify_system \
inotify_system_nodel \
Expand Down Expand Up @@ -515,6 +516,7 @@ msgque: CFLAGS += -DNEW_IPC_NS
sem: CFLAGS += -DNEW_IPC_NS
posix_timers: LDLIBS += -lrt -pthread
remap_dead_pid_root: CFLAGS += -DREMAP_PID_ROOT
sock_filter01: CFLAGS += -DSOCK_FILTER01
socket-tcp6: CFLAGS += -D ZDTM_IPV6
socket-tcp4v6: CFLAGS += -D ZDTM_IPV4V6
socket-tcpbuf6: CFLAGS += -D ZDTM_IPV6
Expand Down
Expand Up @@ -15,12 +15,24 @@ const char *test_author = "Pavel Emelyanov <xemul@parallels.com>";
#define SO_GET_FILTER SO_ATTACH_FILTER
#endif

#ifdef SOCK_FILTER01
#define SFLEN 4
#else
#define SFLEN 14
#endif

int main(int argc, char **argv)
{
int sk;
struct sock_fprog p;
#ifdef SOCK_FILTER01
struct sock_filter f[SFLEN] = {
{ 0x6, 0, 0, 0x0000ffff },
{ 0x6, 0, 0, 0x0000ffff },
{ 0x6, 0, 0, 0x0000ffff },
{ 0x6, 0, 0, 0x0000ffff },
};
#else
struct sock_filter f[SFLEN] = {
{ 0x28, 0, 0, 0x0000000c },
{ 0x15, 0, 4, 0x00000800 },
Expand All @@ -37,6 +49,7 @@ int main(int argc, char **argv)
{ 0x6, 0, 0, 0x0000ffff },
{ 0x6, 0, 0, 0x00000000 },
};
#endif
struct sock_filter f2[SFLEN], f3[SFLEN];
socklen_t len;

Expand Down
1 change: 1 addition & 0 deletions test/zdtm/static/sock_filter01.c