linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@linaro.org>
To: hughd@google.com
Cc: linux-mm@kvack.org
Subject: [bug report] mm/pgtable: allow pte_offset_map[_lock]() to fail
Date: Tue, 11 Jul 2023 10:25:53 +0300	[thread overview]
Message-ID: <3ac58297-c3b4-4ef3-9743-d96a477ac53c@moroto.mountain> (raw)

Hello Hugh Dickins,

The patch 0d940a9b270b: "mm/pgtable: allow pte_offset_map[_lock]() to
fail" from Jun 8, 2023, leads to the following Smatch static checker
warning:

	mm/userfaultfd.c:321 mfill_atomic_pte_poison()
	error: uninitialized symbol 'ptl'.

mm/userfaultfd.c
    292 static int mfill_atomic_pte_poison(pmd_t *dst_pmd,
    293                                    struct vm_area_struct *dst_vma,
    294                                    unsigned long dst_addr,
    295                                    uffd_flags_t flags)
    296 {
    297         int ret;
    298         struct mm_struct *dst_mm = dst_vma->vm_mm;
    299         pte_t _dst_pte, *dst_pte;
    300         spinlock_t *ptl;
    301 
    302         _dst_pte = make_pte_marker(PTE_MARKER_POISONED);
    303         dst_pte = pte_offset_map_lock(dst_mm, dst_pmd, dst_addr, &ptl);
                                                                         ^^^^
The __pte_offset_map_lock() function does not initialize ptl if it
returns NULL.

    304 
    305         if (mfill_file_over_size(dst_vma, dst_addr)) {
    306                 ret = -EFAULT;
    307                 goto out_unlock;
    308         }
    309 
    310         ret = -EEXIST;
    311         /* Refuse to overwrite any PTE, even a PTE marker (e.g. UFFD WP). */
    312         if (!pte_none(*dst_pte))
    313                 goto out_unlock;
    314 
    315         set_pte_at(dst_mm, dst_addr, dst_pte, _dst_pte);
    316 
    317         /* No need to invalidate - it was non-present before */
    318         update_mmu_cache(dst_vma, dst_addr, dst_pte);
    319         ret = 0;
    320 out_unlock:
--> 321         pte_unmap_unlock(dst_pte, ptl);
    322         return ret;
    323 }

regards,
dan carpenter


             reply	other threads:[~2023-07-11  7:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-11  7:25 Dan Carpenter [this message]
2023-07-12  1:23 ` Hugh Dickins
2023-07-12  6:50   ` Dan Carpenter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3ac58297-c3b4-4ef3-9743-d96a477ac53c@moroto.mountain \
    --to=dan.carpenter@linaro.org \
    --cc=hughd@google.com \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox