From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 372E8C433EF for ; Tue, 5 Oct 2021 21:26:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CF5CE60EE9 for ; Tue, 5 Oct 2021 21:26:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CF5CE60EE9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 5E8456B006C; Tue, 5 Oct 2021 17:26:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 571396B0071; Tue, 5 Oct 2021 17:26:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3EC856B0073; Tue, 5 Oct 2021 17:26:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0175.hostedemail.com [216.40.44.175]) by kanga.kvack.org (Postfix) with ESMTP id 2E65E6B006C for ; Tue, 5 Oct 2021 17:26:40 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id D0F012A486 for ; Tue, 5 Oct 2021 21:26:39 +0000 (UTC) X-FDA: 78663668118.13.0282627 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by imf09.hostedemail.com (Postfix) with ESMTP id 668A23000FF1 for ; Tue, 5 Oct 2021 21:26:39 +0000 (UTC) Received: by mail-pl1-f180.google.com with SMTP id x8so302947plv.8 for ; Tue, 05 Oct 2021 14:26:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=a60E67F2xwQSDgkfB8SOszqT0QhHvaT/a+KtU98CG5o=; b=ldYiRVDol+qaHlyrpZsdAykPScw9EK3P3vwJc78IEpvyarji4APkn2SEClBqrqTv7u /pgwxt3usMzVImO8zBrxrY11+IdxaSisvQmzOdq0/RcWql6w/QQWQzWXnsXDMRHlw7hH hJAl8arclcj6A6WcVJoFhVrKMuuqVZpm4zmr0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=a60E67F2xwQSDgkfB8SOszqT0QhHvaT/a+KtU98CG5o=; b=NXQPCngqaGiT+8SPUQqWZ3x1As8rAK2Q/5Ab1Lt2AVnHj+daBHpoMmXwv97p/FAqSN WiqmPXzzKXZQ8xMtC1w8wkUEkmYmeHyQ56bhPYFwQhGGs9lb+geLeJaxNmd3DsK1txcv OdsaFISmxV4gtQVTb130YtS/UajEoYXLlLUq5C5HYCc5E3hozx1h1+RkHkXsXu8G6wz0 tkSA1McfyRPqK7x9g8K5734RvYLwgAcPxuALFIzuXBEC7GwfKGuNXK1ZISPMSD4m+clr PmzjaWsXkAP9II3Q5pNHWh9uZc3wpENkkjf3cmTOoMcf6jQcTymeWhQ1gbzhuMaTZNd0 jaYw== X-Gm-Message-State: AOAM531eJkyowlGePGp9cy7vODcm0n/wuZxD1me3i4886RXH210H/9a7 ZDKBlx+qdcfMKBuvMwujNXfvWg== X-Google-Smtp-Source: ABdhPJwGBuvm6eeyhiepgS3NaKyaW373QwhYQsCFht4TBjs4eY+3C1UYieP+ayB/8tFdwpQdnyVD2A== X-Received: by 2002:a17:90a:29a6:: with SMTP id h35mr6476289pjd.188.1633469198575; Tue, 05 Oct 2021 14:26:38 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id l18sm19191521pfu.202.2021.10.05.14.26.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Oct 2021 14:26:38 -0700 (PDT) Date: Tue, 5 Oct 2021 14:26:37 -0700 From: Kees Cook To: "Matthew Wilcox (Oracle)" Cc: linux-mm@kvack.org, Thomas Gleixner Subject: Re: [PATCH 3/3] mm/usercopy: Detect compound page overruns Message-ID: <202110051425.ABFA413@keescook> References: <20211004224224.4137992-1-willy@infradead.org> <20211004224224.4137992-4-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211004224224.4137992-4-willy@infradead.org> X-Rspamd-Queue-Id: 668A23000FF1 X-Stat-Signature: 9da81c3611ed3ci8kfaxkfyfqo67oox5 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=ldYiRVDo; spf=pass (imf09.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.180 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam06 X-HE-Tag: 1633469199-489090 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Oct 04, 2021 at 11:42:23PM +0100, Matthew Wilcox (Oracle) wrote: > Move the compound page overrun detection out of > CONFIG_HARDENED_USERCOPY_PAGESPAN so it's enabled for more people. > > Signed-off-by: Matthew Wilcox (Oracle) > --- > mm/usercopy.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/mm/usercopy.c b/mm/usercopy.c > index 7bfc4f9ed1e4..e395462961d5 100644 > --- a/mm/usercopy.c > +++ b/mm/usercopy.c > @@ -194,11 +194,6 @@ static inline void check_page_span(const void *ptr, unsigned long n, > ((unsigned long)end & (unsigned long)PAGE_MASK))) > return; > > - /* Allow if fully inside the same compound (__GFP_COMP) page. */ > - endpage = virt_to_head_page(end); > - if (likely(endpage == page)) > - return; > - > /* > * Reject if range is entirely either Reserved (i.e. special or > * device memory), or CMA. Otherwise, reject since the object spans > @@ -250,6 +245,10 @@ static inline void check_heap_object(const void *ptr, unsigned long n, > if (PageSlab(page)) { > /* Check slab allocator for flags and size. */ > __check_heap_object(ptr, n, page, to_user); > + } else if (PageHead(page)) { > + /* A compound allocation */ > + if (ptr + n > page_address(page) + page_size(page)) > + usercopy_abort("page alloc", NULL, to_user, 0, n); "0" could be "ptr - page_address(page)", I think? With that: Acked-by: Kees Cook -Kees > } else { > /* Verify object does not incorrectly span multiple pages. */ > check_page_span(ptr, n, page, to_user); > -- > 2.32.0 > -- Kees Cook