Skip to content

Commit 848b165

Browse files
avaginCyrill Gorcunov
authored and
Cyrill Gorcunov
committed
unix: a unix name can be a non-null terminated string
In this patch, we replace all zero characters to '@'. ==30==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60300000e3ca at pc 0x7f34144b6be1 bp 0x7ffee7b6bb20 sp 0x7ffee7b6b298 READ of size 26 at 0x60300000e3ca thread T0 #0 0x7f34144b6be0 (/lib64/libasan.so.3+0x8dbe0) checkpoint-restore#1 0x7f34144b8e4d in __interceptor_vsnprintf (/lib64/libasan.so.3+0x8fe4d) checkpoint-restore#2 0x4966cb in vprint_on_level criu/log.c:228 checkpoint-restore#3 0x496b64 in print_on_level criu/log.c:249 checkpoint-restore#4 0x505c94 in collect_one_unixsk criu/sk-unix.c:1401 checkpoint-restore#5 0x4e7ae3 in collect_image criu/protobuf.c:213 checkpoint-restore#6 0x462c5c in root_prepare_shared criu/cr-restore.c:247 checkpoint-restore#7 0x462c5c in restore_task_with_children criu/cr-restore.c:1420 checkpoint-restore#8 0x7f34132d70ec in __clone (/lib64/libc.so.6+0x1030ec) 0x60300000e3ca is located 0 bytes to the right of 26-byte region [0x60300000e3b0,0x60300000e3ca) allocated by thread T0 here: #0 0x7f34144efe70 in malloc (/lib64/libasan.so.3+0xc6e70) checkpoint-restore#1 0x7f3413bdb021 (/lib64/libprotobuf-c.so.1+0x6021) Signed-off-by: Andrei Vagin <[email protected]>
1 parent 27a83db commit 848b165

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

criu/sk-unix.c

+29-2
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,9 @@ static int bind_unix_sk(int sk, struct unix_sk_info *ui)
999999
int cwd_fd = -1, root_fd = -1;
10001000
int ret = -1;
10011001

1002+
if (ui->ue->name.len == 0)
1003+
return 0;
1004+
10021005
if ((ui->ue->type == SOCK_STREAM) && (ui->ue->state == TCP_ESTABLISHED)) {
10031006
/*
10041007
* FIXME this can be done, but for doing this properly we
@@ -1396,6 +1399,8 @@ static int collect_one_unixsk(void *o, ProtobufCMessage *base, struct cr_img *i)
13961399
{
13971400
struct unix_sk_info *ui = o;
13981401
static bool post_queued = false;
1402+
char *uname, *prefix = "";
1403+
int ulen;
13991404

14001405
ui->ue = pb_msg(base, UnixSkEntry);
14011406
ui->name_dir = (void *)ui->ue->name_dir;
@@ -1425,10 +1430,32 @@ static int collect_one_unixsk(void *o, ProtobufCMessage *base, struct cr_img *i)
14251430
INIT_LIST_HEAD(&ui->connected);
14261431
INIT_LIST_HEAD(&ui->node);
14271432
ui->flags = 0;
1428-
pr_info(" `- Got %#x peer %#x (name %s dir %s)\n",
1433+
1434+
uname = ui->name;
1435+
ulen = ui->ue->name.len;
1436+
if (ulen > 0 && uname[0] == 0) {
1437+
prefix = "@";
1438+
uname++;
1439+
ulen--;
1440+
if (memrchr(uname, 0, ulen)) {
1441+
/* replace zero characters */
1442+
char *s = alloca(ulen + 1);
1443+
int i;
1444+
1445+
for (i = 0; i < ulen; i++)
1446+
s[i] = uname[i] ? : '@';
1447+
uname = s;
1448+
}
1449+
} else if (ulen == 0) {
1450+
ulen = 1;
1451+
uname = "-";
1452+
}
1453+
1454+
pr_info(" `- Got %#x peer %#x (name %s%.*s dir %s)\n",
14291455
ui->ue->ino, ui->ue->peer,
1430-
ui->name ? (ui->name[0] ? ui->name : &ui->name[1]) : "-",
1456+
prefix, ulen, uname,
14311457
ui->name_dir ? ui->name_dir : "-");
1458+
14321459
list_add_tail(&ui->list, &unix_sockets);
14331460
return file_desc_add(&ui->d, ui->ue->id, &unix_desc_ops);
14341461
}

0 commit comments

Comments
 (0)