aboutsummaryrefslogtreecommitdiffstats
path: root/fs/fcntl.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/fcntl.c')
-rw-r--r--fs/fcntl.c42
1 files changed, 17 insertions, 25 deletions
diff --git a/fs/fcntl.c b/fs/fcntl.c
index d078b75572a7..81b70e665bf0 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -442,28 +442,24 @@ static int check_fcntl_cmd(unsigned cmd)
442SYSCALL_DEFINE3(fcntl, unsigned int, fd, unsigned int, cmd, unsigned long, arg) 442SYSCALL_DEFINE3(fcntl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)
443{ 443{
444 struct file *filp; 444 struct file *filp;
445 int fput_needed;
445 long err = -EBADF; 446 long err = -EBADF;
446 447
447 filp = fget_raw(fd); 448 filp = fget_raw_light(fd, &fput_needed);
448 if (!filp) 449 if (!filp)
449 goto out; 450 goto out;
450 451
451 if (unlikely(filp->f_mode & FMODE_PATH)) { 452 if (unlikely(filp->f_mode & FMODE_PATH)) {
452 if (!check_fcntl_cmd(cmd)) { 453 if (!check_fcntl_cmd(cmd))
453 fput(filp); 454 goto out1;
454 goto out;
455 }
456 } 455 }
457 456
458 err = security_file_fcntl(filp, cmd, arg); 457 err = security_file_fcntl(filp, cmd, arg);
459 if (err) { 458 if (!err)
460 fput(filp); 459 err = do_fcntl(fd, cmd, arg, filp);
461 return err;
462 }
463 460
464 err = do_fcntl(fd, cmd, arg, filp); 461out1:
465 462 fput_light(filp, fput_needed);
466 fput(filp);
467out: 463out:
468 return err; 464 return err;
469} 465}
@@ -473,26 +469,21 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
473 unsigned long, arg) 469 unsigned long, arg)
474{ 470{
475 struct file * filp; 471 struct file * filp;
476 long err; 472 long err = -EBADF;
473 int fput_needed;
477 474
478 err = -EBADF; 475 filp = fget_raw_light(fd, &fput_needed);
479 filp = fget_raw(fd);
480 if (!filp) 476 if (!filp)
481 goto out; 477 goto out;
482 478
483 if (unlikely(filp->f_mode & FMODE_PATH)) { 479 if (unlikely(filp->f_mode & FMODE_PATH)) {
484 if (!check_fcntl_cmd(cmd)) { 480 if (!check_fcntl_cmd(cmd))
485 fput(filp); 481 goto out1;
486 goto out;
487 }
488 } 482 }
489 483
490 err = security_file_fcntl(filp, cmd, arg); 484 err = security_file_fcntl(filp, cmd, arg);
491 if (err) { 485 if (err)
492 fput(filp); 486 goto out1;
493 return err;
494 }
495 err = -EBADF;
496 487
497 switch (cmd) { 488 switch (cmd) {
498 case F_GETLK64: 489 case F_GETLK64:
@@ -507,7 +498,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
507 err = do_fcntl(fd, cmd, arg, filp); 498 err = do_fcntl(fd, cmd, arg, filp);
508 break; 499 break;
509 } 500 }
510 fput(filp); 501out1:
502 fput_light(filp, fput_needed);
511out: 503out:
512 return err; 504 return err;
513} 505}