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 17FFCC433EF for ; Tue, 5 Oct 2021 21:25:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A37FC6120A for ; Tue, 5 Oct 2021 21:25:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A37FC6120A 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 352CC6B006C; Tue, 5 Oct 2021 17:25:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3017B6B0071; Tue, 5 Oct 2021 17:25:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F02A6B0073; Tue, 5 Oct 2021 17:25:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0090.hostedemail.com [216.40.44.90]) by kanga.kvack.org (Postfix) with ESMTP id 10DE66B006C for ; Tue, 5 Oct 2021 17:25:26 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id C8B602FD87 for ; Tue, 5 Oct 2021 21:25:25 +0000 (UTC) X-FDA: 78663665010.05.88A4922 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by imf08.hostedemail.com (Postfix) with ESMTP id 6C9D53001873 for ; Tue, 5 Oct 2021 21:25:25 +0000 (UTC) Received: by mail-pj1-f45.google.com with SMTP id g13-20020a17090a3c8d00b00196286963b9so2968504pjc.3 for ; Tue, 05 Oct 2021 14:25:25 -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=MmKLKQUxBSMKW22W/TnqDIl2CmDyjnJY8nKlh0FECjk=; b=XsTxRR+H2O8XUqDkCUeLU0kDUbmTRkHGeHyRhgxnf5mbo6d1vqG56uKLBnA9A+GHJU 7tN65LCfHJfsC/rQVwg1DUtCLVYAPSeZsudzjWoGy49bOBe9IZR5vu+/5M7ITnnbPod6 yvmGj7cftEqv6WCjoKNT4o+oyr8Hki//kowBY= 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=MmKLKQUxBSMKW22W/TnqDIl2CmDyjnJY8nKlh0FECjk=; b=SM8mqWFPUn7vnYSXSMGVvR2O3laAf7nqj6jXJ+CZUuwnW9dSTQET0SrBWirSI5kyuu 4waifUvLK7uEkBzp0QLm0uNwo7BOCOaOhWfySBJH9X/hbxYE+n3VQ1krelTOc1v/up+6 tHDLzREhrwE57HyH0MJIEUetNaPQrCbbDw+nTVtDwjIpagLwsIqH16x1dpWkc58/+v7C q6KCuP1m2l8RdbnN+7dt1pZ5rmFFdruKpT1p6+knzvzURynVvpLT7hcPFEZ+v6ZyuFzm dpCRuVL/ivKlhj2KpzS2GWA4oV4pR8bUgCwjwcB2xb+tE3tbQcGpguRXn3edTQyWjHp9 lWoA== X-Gm-Message-State: AOAM530oh7njDjq5wWtH78rl9zMWEU/bxFEc5ZaKYmF31ZLm2emhJ3DN knZEFpcs5hgBlJZF5ZFLVRT27Q== X-Google-Smtp-Source: ABdhPJyKYhRNhqUdjfMAQYaxJdZq7xf/NvF7GXepO29M1zYLJV0DTEPJikhOKcUO4ZYCuZAYErQ4Dg== X-Received: by 2002:a17:90a:191a:: with SMTP id 26mr6471125pjg.118.1633469124519; Tue, 05 Oct 2021 14:25:24 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id y13sm19012728pgc.46.2021.10.05.14.25.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Oct 2021 14:25:24 -0700 (PDT) Date: Tue, 5 Oct 2021 14:25:23 -0700 From: Kees Cook To: "Matthew Wilcox (Oracle)" Cc: linux-mm@kvack.org, Thomas Gleixner Subject: Re: [PATCH 2/3] mm/usercopy: Detect vmalloc overruns Message-ID: <202110051423.9F6F93752@keescook> References: <20211004224224.4137992-1-willy@infradead.org> <20211004224224.4137992-3-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211004224224.4137992-3-willy@infradead.org> X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 6C9D53001873 X-Stat-Signature: n7xu6skkx1i5n35394omceqfrqrw54b4 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=XsTxRR+H; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf08.hostedemail.com: domain of keescook@chromium.org designates 209.85.216.45 as permitted sender) smtp.mailfrom=keescook@chromium.org X-HE-Tag: 1633469125-681119 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:22PM +0100, Matthew Wilcox (Oracle) wrote: > If you have a vmalloc() allocation, or an address from calling vmap(), > you cannot overrun the vm_area which describes it, regardless of the > size of the underlying allocation. This probably doesn't do much for > security because vmalloc comes with guard pages these days, but it > prevents usercopy aborts when copying to a vmap() of smaller pages. > > Signed-off-by: Matthew Wilcox (Oracle) > --- > mm/usercopy.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/mm/usercopy.c b/mm/usercopy.c > index ac95b22fbbce..7bfc4f9ed1e4 100644 > --- a/mm/usercopy.c > +++ b/mm/usercopy.c > @@ -17,6 +17,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -236,6 +237,14 @@ static inline void check_heap_object(const void *ptr, unsigned long n, > return; > } > > + if (is_vmalloc_addr(ptr)) { > + struct vm_struct *vm = find_vm_area(ptr); > + > + if (ptr + n > vm->addr + vm->size) > + usercopy_abort("vmalloc", NULL, to_user, 0, n); This "0" is easy to make "ptr - vm->addr". With that fixed: Acked-by: Kees Cook -Kees > + return; > + } > + > page = virt_to_head_page(ptr); > > if (PageSlab(page)) { > -- > 2.32.0 > -- Kees Cook