aboutsummaryrefslogtreecommitdiffstats
path: root/net/socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/socket.c')
-rw-r--r--net/socket.c123
1 files changed, 56 insertions, 67 deletions
diff --git a/net/socket.c b/net/socket.c
index 42d8e9c9ccd5..6f05d5c4bf30 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -406,8 +406,10 @@ struct file *sock_alloc_file(struct socket *sock, int flags, const char *dname)
406 name.len = strlen(name.name); 406 name.len = strlen(name.name);
407 } 407 }
408 path.dentry = d_alloc_pseudo(sock_mnt->mnt_sb, &name); 408 path.dentry = d_alloc_pseudo(sock_mnt->mnt_sb, &name);
409 if (unlikely(!path.dentry)) 409 if (unlikely(!path.dentry)) {
410 sock_release(sock);
410 return ERR_PTR(-ENOMEM); 411 return ERR_PTR(-ENOMEM);
412 }
411 path.mnt = mntget(sock_mnt); 413 path.mnt = mntget(sock_mnt);
412 414
413 d_instantiate(path.dentry, SOCK_INODE(sock)); 415 d_instantiate(path.dentry, SOCK_INODE(sock));
@@ -415,9 +417,11 @@ struct file *sock_alloc_file(struct socket *sock, int flags, const char *dname)
415 file = alloc_file(&path, FMODE_READ | FMODE_WRITE, 417 file = alloc_file(&path, FMODE_READ | FMODE_WRITE,
416 &socket_file_ops); 418 &socket_file_ops);
417 if (IS_ERR(file)) { 419 if (IS_ERR(file)) {
418 /* drop dentry, keep inode */ 420 /* drop dentry, keep inode for a bit */
419 ihold(d_inode(path.dentry)); 421 ihold(d_inode(path.dentry));
420 path_put(&path); 422 path_put(&path);
423 /* ... and now kill it properly */
424 sock_release(sock);
421 return file; 425 return file;
422 } 426 }
423 427
@@ -432,8 +436,10 @@ static int sock_map_fd(struct socket *sock, int flags)
432{ 436{
433 struct file *newfile; 437 struct file *newfile;
434 int fd = get_unused_fd_flags(flags); 438 int fd = get_unused_fd_flags(flags);
435 if (unlikely(fd < 0)) 439 if (unlikely(fd < 0)) {
440 sock_release(sock);
436 return fd; 441 return fd;
442 }
437 443
438 newfile = sock_alloc_file(sock, flags, NULL); 444 newfile = sock_alloc_file(sock, flags, NULL);
439 if (likely(!IS_ERR(newfile))) { 445 if (likely(!IS_ERR(newfile))) {
@@ -1330,19 +1336,9 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
1330 1336
1331 retval = sock_create(family, type, protocol, &sock); 1337 retval = sock_create(family, type, protocol, &sock);
1332 if (retval < 0) 1338 if (retval < 0)
1333 goto out; 1339 return retval;
1334
1335 retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
1336 if (retval < 0)
1337 goto out_release;
1338
1339out:
1340 /* It may be already another descriptor 8) Not kernel problem. */
1341 return retval;
1342 1340
1343out_release: 1341 return sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
1344 sock_release(sock);
1345 return retval;
1346} 1342}
1347 1343
1348/* 1344/*
@@ -1366,87 +1362,72 @@ SYSCALL_DEFINE4(socketpair, int, family, int, type, int, protocol,
1366 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK; 1362 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
1367 1363
1368 /* 1364 /*
1365 * reserve descriptors and make sure we won't fail
1366 * to return them to userland.
1367 */
1368 fd1 = get_unused_fd_flags(flags);
1369 if (unlikely(fd1 < 0))
1370 return fd1;
1371
1372 fd2 = get_unused_fd_flags(flags);
1373 if (unlikely(fd2 < 0)) {
1374 put_unused_fd(fd1);
1375 return fd2;
1376 }
1377
1378 err = put_user(fd1, &usockvec[0]);
1379 if (err)
1380 goto out;
1381
1382 err = put_user(fd2, &usockvec[1]);
1383 if (err)
1384 goto out;
1385
1386 /*
1369 * Obtain the first socket and check if the underlying protocol 1387 * Obtain the first socket and check if the underlying protocol
1370 * supports the socketpair call. 1388 * supports the socketpair call.
1371 */ 1389 */
1372 1390
1373 err = sock_create(family, type, protocol, &sock1); 1391 err = sock_create(family, type, protocol, &sock1);
1374 if (err < 0) 1392 if (unlikely(err < 0))
1375 goto out; 1393 goto out;
1376 1394
1377 err = sock_create(family, type, protocol, &sock2); 1395 err = sock_create(family, type, protocol, &sock2);
1378 if (err < 0) 1396 if (unlikely(err < 0)) {
1379 goto out_release_1; 1397 sock_release(sock1);
1380 1398 goto out;
1381 err = sock1->ops->socketpair(sock1, sock2);
1382 if (err < 0)
1383 goto out_release_both;
1384
1385 fd1 = get_unused_fd_flags(flags);
1386 if (unlikely(fd1 < 0)) {
1387 err = fd1;
1388 goto out_release_both;
1389 } 1399 }
1390 1400
1391 fd2 = get_unused_fd_flags(flags); 1401 err = sock1->ops->socketpair(sock1, sock2);
1392 if (unlikely(fd2 < 0)) { 1402 if (unlikely(err < 0)) {
1393 err = fd2; 1403 sock_release(sock2);
1394 goto out_put_unused_1; 1404 sock_release(sock1);
1405 goto out;
1395 } 1406 }
1396 1407
1397 newfile1 = sock_alloc_file(sock1, flags, NULL); 1408 newfile1 = sock_alloc_file(sock1, flags, NULL);
1398 if (IS_ERR(newfile1)) { 1409 if (IS_ERR(newfile1)) {
1399 err = PTR_ERR(newfile1); 1410 err = PTR_ERR(newfile1);
1400 goto out_put_unused_both; 1411 sock_release(sock2);
1412 goto out;
1401 } 1413 }
1402 1414
1403 newfile2 = sock_alloc_file(sock2, flags, NULL); 1415 newfile2 = sock_alloc_file(sock2, flags, NULL);
1404 if (IS_ERR(newfile2)) { 1416 if (IS_ERR(newfile2)) {
1405 err = PTR_ERR(newfile2); 1417 err = PTR_ERR(newfile2);
1406 goto out_fput_1; 1418 fput(newfile1);
1419 goto out;
1407 } 1420 }
1408 1421
1409 err = put_user(fd1, &usockvec[0]);
1410 if (err)
1411 goto out_fput_both;
1412
1413 err = put_user(fd2, &usockvec[1]);
1414 if (err)
1415 goto out_fput_both;
1416
1417 audit_fd_pair(fd1, fd2); 1422 audit_fd_pair(fd1, fd2);
1418 1423
1419 fd_install(fd1, newfile1); 1424 fd_install(fd1, newfile1);
1420 fd_install(fd2, newfile2); 1425 fd_install(fd2, newfile2);
1421 /* fd1 and fd2 may be already another descriptors.
1422 * Not kernel problem.
1423 */
1424
1425 return 0; 1426 return 0;
1426 1427
1427out_fput_both: 1428out:
1428 fput(newfile2);
1429 fput(newfile1);
1430 put_unused_fd(fd2);
1431 put_unused_fd(fd1);
1432 goto out;
1433
1434out_fput_1:
1435 fput(newfile1);
1436 put_unused_fd(fd2);
1437 put_unused_fd(fd1);
1438 sock_release(sock2);
1439 goto out;
1440
1441out_put_unused_both:
1442 put_unused_fd(fd2); 1429 put_unused_fd(fd2);
1443out_put_unused_1:
1444 put_unused_fd(fd1); 1430 put_unused_fd(fd1);
1445out_release_both:
1446 sock_release(sock2);
1447out_release_1:
1448 sock_release(sock1);
1449out:
1450 return err; 1431 return err;
1451} 1432}
1452 1433
@@ -1562,7 +1543,6 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
1562 if (IS_ERR(newfile)) { 1543 if (IS_ERR(newfile)) {
1563 err = PTR_ERR(newfile); 1544 err = PTR_ERR(newfile);
1564 put_unused_fd(newfd); 1545 put_unused_fd(newfd);
1565 sock_release(newsock);
1566 goto out_put; 1546 goto out_put;
1567 } 1547 }
1568 1548
@@ -2641,6 +2621,15 @@ out_fs:
2641 2621
2642core_initcall(sock_init); /* early initcall */ 2622core_initcall(sock_init); /* early initcall */
2643 2623
2624static int __init jit_init(void)
2625{
2626#ifdef CONFIG_BPF_JIT_ALWAYS_ON
2627 bpf_jit_enable = 1;
2628#endif
2629 return 0;
2630}
2631pure_initcall(jit_init);
2632
2644#ifdef CONFIG_PROC_FS 2633#ifdef CONFIG_PROC_FS
2645void socket_seq_show(struct seq_file *seq) 2634void socket_seq_show(struct seq_file *seq)
2646{ 2635{