lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 20 Jul 2023 12:03:10 -0700
From:   Nick Desaulniers <ndesaulniers@...gle.com>
To:     Linke Li <lilinke99@...mail.com>
Cc:     linux-mm@...ck.org, mike.kravetz@...cle.com, muchun.song@...ux.dev,
        nathan@...nel.org, trix@...hat.com, linux-kernel@...r.kernel.org,
        llvm@...ts.linux.dev, dan.carpenter@...aro.org,
        Linke Li <lilinke99@...il.com>
Subject: Re: [PATCH v3] hugetlbfs: Fix integer overflow check in hugetlbfs_file_mmap()

On Thu, Jul 20, 2023 at 7:50 AM Linke Li <lilinke99@...mail.com> wrote:
>
> From: Linke Li <lilinke99@...il.com>
>
> ```
>         vma_len = (loff_t)(vma->vm_end - vma->vm_start);
>         len = vma_len + ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
>         /* check for overflow */
>         if (len < vma_len)
>                 return -EINVAL;
> ```
>
> There is a signed integer overflow in the code, which is undefined
> behavior according to the C stacnard. Although this works, it's

typo: s/stacnard/standard/

I think the commit message should explicitly mention that the Linux
kernel is built with -fno-strict-overflow, but IMO that kind of makes
this patch moot.

> still a bit ugly and static checkers will complain.
>
> Using macro "check_add_overflow" to do the overflow check can
> effectively detect integer overflow and avoid any undefined behavior.
>
> Signed-off-by: Linke Li <lilinke99@...il.com>
> ---
> v3: fix checkpatch warning and better description.
>  fs/hugetlbfs/inode.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
> index 7b17ccfa039d..326a8c0af5f6 100644
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -154,10 +154,7 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)
>         if (vma->vm_pgoff & (~huge_page_mask(h) >> PAGE_SHIFT))
>                 return -EINVAL;
>
> -       vma_len = (loff_t)(vma->vm_end - vma->vm_start);
> -       len = vma_len + ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
> -       /* check for overflow */
> -       if (len < vma_len)
> +       if (check_add_overflow(vma_len, (loff_t)vma->vm_pgoff << PAGE_SHIFT, &len))
>                 return -EINVAL;
>
>         inode_lock(inode);
> --
> 2.25.1
>


-- 
Thanks,
~Nick Desaulniers

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ