Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0DF0C61DA4 for ; Thu, 16 Feb 2023 09:49:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230059AbjBPJtJ (ORCPT ); Thu, 16 Feb 2023 04:49:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229998AbjBPJtC (ORCPT ); Thu, 16 Feb 2023 04:49:02 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEB62212A8 for ; Thu, 16 Feb 2023 01:49:00 -0800 (PST) Received: from [192.168.10.12] (unknown [39.45.217.110]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madras.collabora.co.uk (Postfix) with ESMTPSA id ECD37660219B; Thu, 16 Feb 2023 09:48:57 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1676540939; bh=PX8dOl30j3Yr0k0JAknV8dpZqe1VdlzvplpwBLPzdKc=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=H5v4ZpM/z+wrQUpEW5xK3yLSyNMR0XOXYFHJm9aBPg6Ze0M6QB+Yehh9TffL/TsgJ U/WkkBKQ3mZzJpky43EowepFh60QwCIA2bs0+cQOmI9RPBSkUE34dumQbB5gWwh7qK dHzIqN2OS5SPKKquYugbRwUcPJ5UmeKyoZhhxsFWm1z3NBRjio2bREYV36Yj5UUntK BwVsSYglk00vNqe9Nm6tigdcqXGI+8j1OwF8AMu5qOAv8OQiD2EWtYW2fOlxNOa9lt QwFBvfsyxNQX9YdZ55BYpdyO+nO5VRmcU/uiFlVGpBl4WeHTHtdcwvidj2dct8z20U l1amKTZJEEPeg== Message-ID: Date: Thu, 16 Feb 2023 14:48:51 +0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Cc: Muhammad Usama Anjum , kernel@collabora.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 2/2] mm/userfaultfd: add VM_WARN_ONCE() Content-Language: en-US To: David Hildenbrand , peterx@redhat.com, Andrew Morton References: <20230216091656.2045471-1-usama.anjum@collabora.com> <20230216091656.2045471-2-usama.anjum@collabora.com> <4d29a9ec-027d-06b9-8543-87d386e58c94@redhat.com> From: Muhammad Usama Anjum In-Reply-To: <4d29a9ec-027d-06b9-8543-87d386e58c94@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/16/23 2:24 PM, David Hildenbrand wrote: > On 16.02.23 10:16, Muhammad Usama Anjum wrote: >> Add VM_WARN_ONCE() to uffd_wp_range() to detect range (start, len) abuse. >> >> Signed-off-by: Muhammad Usama Anjum >> --- >>   mm/userfaultfd.c | 2 ++ >>   1 file changed, 2 insertions(+) >> >> diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c >> index 77c5839e591c..d89ed44d2668 100644 >> --- a/mm/userfaultfd.c >> +++ b/mm/userfaultfd.c >> @@ -717,6 +717,8 @@ long uffd_wp_range(struct mm_struct *dst_mm, struct >> vm_area_struct *dst_vma, >>       struct mmu_gather tlb; >>       long ret; >>   +    VM_WARN_ONCE(start < dst_vma->vm_start || start + len > >> dst_vma->vm_end, >> +             "The address range exceeds VMA boundary.\n"); > > VM_WARN_ON_ONCE is sufficient (sorry for spelling out the wrong variant > earlier). Will do in the next version. Thanks. > > These kinds of bugs are expected to be found early during testing, still it > might make sense to implement a backup path > > if (WARN_ON_ONCE(...)) >     return -EINVAL; > > But we can't use VM_WARN_ON_ONCE here, so we can't compile it out anymore > ... so I guess a simple VM_WARN_ON_ONCE() is sufficient. > -- BR, Muhammad Usama Anjum