[CRIU] [PATCH v5 0/4] c/r of file leases

Pavel Begunkov asml.silence at gmail.com
Thu Feb 8 21:43:57 MSK 2018


Hello, this is a false positive. I think the analyser got confused
because of hi-order functions and the dual nature of descriptors
(negative ranges encode errors).
I'll look how to circumvent it a bit later.

On 08/02/18 20:56, Andrei Vagin wrote:
> Pavel, could you take a look at this coverity issue?
> 
> 611static int restore_file_lock(FileLockEntry *fle)
> 612{
> 613        int ret = -1;
> 614        unsigned int cmd;
> 615
>    	1. Condition fle->flag & 2, taking false branch.
> 616        if (fle->flag & FL_FLOCK) {
> 617                if (fle->type & LOCK_MAND) {
> 618                        cmd = fle->type;
> 619                } else if (fle->type == F_RDLCK) {
> 620                        cmd = LOCK_SH;
> 621                } else if (fle->type == F_WRLCK) {
> 622                        cmd = LOCK_EX;
> 623                } else if (fle->type == F_UNLCK) {
> 624                        cmd = LOCK_UN;
> 625                } else {
> 626                        pr_err("Unknown flock type!\n");
> 627                        goto err;
> 628                }
> 629
> 630                pr_info("(flock)flag: %d, type: %d, cmd: %d, pid: %d, fd: %d\n",
> 631                        fle->flag, fle->type, cmd, fle->pid, fle->fd);
> 632
> 633                ret = flock(fle->fd, cmd);
> 634                if (ret < 0) {
> 635                        pr_err("Can not set flock!\n");
> 636                        goto err;
> 637                }
>    	2. Condition fle->flag & 1, taking false branch.
> 638        } else if (fle->flag & FL_POSIX) {
> 639                struct flock flk;
> 640                memset(&flk, 0, sizeof(flk));
> 641
> 642                flk.l_whence = SEEK_SET;
> 643                flk.l_start  = fle->start;
> 644                flk.l_len    = fle->len;
> 645                flk.l_pid    = fle->pid;
> 646                flk.l_type   = fle->type;
> 647
> 648                pr_info("(posix)flag: %d, type: %d, pid: %d, fd: %d, "
> 649                        "start: %8"PRIx64", len: %8"PRIx64"\n",
> 650                        fle->flag, fle->type, fle->pid, fle->fd,
> 651                        fle->start, fle->len);
> 652
> 653                ret = fcntl(fle->fd, F_SETLKW, &flk);
> 654                if (ret < 0) {
> 655                        pr_err("Can not set posix lock!\n");
> 656                        goto err;
> 657                }
>    	3. Condition fle->flag & 4, taking false branch.
> 658        } else if (fle->flag & FL_OFD) {
> 659                struct flock flk = {
> 660                        .l_whence = SEEK_SET,
> 661                        .l_start  = fle->start,
> 662                        .l_len    = fle->len,
> 663                        .l_pid    = 0,
> 664                        .l_type   = fle->type
> 665                };
> 666
> 667                pr_info("(ofd)flag: %d, type: %d, pid: %d, fd: %d, "
> 668                                "start: %8"PRIx64", len: %8"PRIx64"\n",
> 669                                fle->flag, fle->type, fle->pid, fle->fd,
> 670                                fle->start, fle->len);
> 671
> 672                ret = fcntl(fle->fd, F_OFD_SETLK, &flk);
> 673                if (ret < 0) {
> 674                        pr_err("Can not set ofd lock!\n");
> 675                        goto err;
> 676                }
>    	4. Condition fle->flag & 8, taking true branch.
> 677        } else if (fle->flag & FL_LEASE) {
> 678                pr_info("(lease)flag: %d, type: %d, pid: %d, fd: %d, "
> 679                                "start: %8"PRIx64", len: %8"PRIx64"\n",
> 680                        fle->flag, fle->type, fle->pid, fle->fd,
> 681                        fle->start, fle->len);
>    	5. open_fn: Returning handle opened by restore_file_lease. [show details]
>    	6. var_assign: Assigning: ret = handle returned from restore_file_lease(fle).
> 682                ret = restore_file_lease(fle);
>    	7. Condition ret < 0, taking false branch.
> 683                if (ret < 0)
> 684                        goto err;
>    	8. Falling through to end of if statement.
> 685        } else {
> 686                pr_err("Unknown file lock style!\n");
> 687                goto err;
> 688        }
> 689
>    	
> CID 185303 (#1 of 1): Resource leak (RESOURCE_LEAK)
> 9. leaked_handle: Handle variable ret going out of scope leaks the handle.
> 690        return 0;
> 691err:
> 692        return ret;
> 693}
> 
> On Mon, Oct 02, 2017 at 11:48:16PM +0300, Pavel Begunkov wrote:
>> The patchset adds full support of file leases:
>> - procfs parsing changes
>> - restoring of file leases. In case of broken leases it breaks
>> established lease with open syscall.
>> - workaround inane 'broken lease type' (always 'READ') in procfs.
>> - logic to support missing info about leases in proc/fd (v4.0 or older)
>> - zdtm tests
>>
>> Pavel Begunkov (4):
>>   locks: Add c/r of non broken leases (kernel>=v4.1)
>>   locks: Add c/r of breaking leases (kernel>=v4.1)
>>   locks: Add leases c/r for kernels v4.0 and older
>>   zdtm: Add file lease tests
>>
>>  criu/file-lock.c                   | 275 +++++++++++++++++++++++++++++++++++++
>>  criu/files.c                       |   3 +
>>  criu/include/file-lock.h           |   7 +
>>  criu/proc_parse.c                  |   8 ++
>>  test/zdtm/static/Makefile          |   4 +
>>  test/zdtm/static/file_lease00.c    |  84 +++++++++++
>>  test/zdtm/static/file_lease00.desc |   1 +
>>  test/zdtm/static/file_lease01.c    |  88 ++++++++++++
>>  test/zdtm/static/file_lease01.desc |   1 +
>>  test/zdtm/static/file_lease02.c    | 145 +++++++++++++++++++
>>  test/zdtm/static/file_lease02.desc |   1 +
>>  test/zdtm/static/file_lease03.c    | 145 +++++++++++++++++++
>>  test/zdtm/static/file_lease03.desc |   1 +
>>  13 files changed, 763 insertions(+)
>>  create mode 100644 test/zdtm/static/file_lease00.c
>>  create mode 100644 test/zdtm/static/file_lease00.desc
>>  create mode 100644 test/zdtm/static/file_lease01.c
>>  create mode 120000 test/zdtm/static/file_lease01.desc
>>  create mode 100644 test/zdtm/static/file_lease02.c
>>  create mode 120000 test/zdtm/static/file_lease02.desc
>>  create mode 100644 test/zdtm/static/file_lease03.c
>>  create mode 120000 test/zdtm/static/file_lease03.desc
>>
>> -- 
>> 2.14.1.473.g3ec7d702a8
>>
>> _______________________________________________
>> CRIU mailing list
>> CRIU at openvz.org
>> https://lists.openvz.org/mailman/listinfo/criu

-- 
Yours sincerely,
Pavel (silence)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.openvz.org/pipermail/criu/attachments/20180208/2cc1cdc0/attachment.sig>


More information about the CRIU mailing list