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 5BB0FC433F5 for ; Tue, 5 Oct 2021 21:54:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CA6206117A for ; Tue, 5 Oct 2021 21:54:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CA6206117A 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 550AF6B006C; Tue, 5 Oct 2021 17:54:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 500496B0071; Tue, 5 Oct 2021 17:54:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3EEFF6B0073; Tue, 5 Oct 2021 17:54:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0106.hostedemail.com [216.40.44.106]) by kanga.kvack.org (Postfix) with ESMTP id 2D24F6B006C for ; Tue, 5 Oct 2021 17:54:16 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id DE33739B0C for ; Tue, 5 Oct 2021 21:54:15 +0000 (UTC) X-FDA: 78663737670.21.CC34305 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf13.hostedemail.com (Postfix) with ESMTP id 87611103A712 for ; Tue, 5 Oct 2021 21:54:15 +0000 (UTC) Received: by mail-pf1-f182.google.com with SMTP id h1so632060pfv.12 for ; Tue, 05 Oct 2021 14:54:15 -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=gk0Sv0QVeYT5B3l1bhAiakkTWpV2dUzz4L/G6mzjuQk=; b=Qold4IGQyy+9W7JqvAUJ8RxmRJh252C6ua68voxS0XWWw0N/twFUvW8DSs0igbjl2V +BRWYWksrrROuaAmzmPv5ixcWVXiH3pHNCyNziiskvlB/+ODpLMKsLxlVI1oqslsHNkQ JD/idvnHoXvdMAmmapdwXKTPB16pqnTHPfGpw= 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=gk0Sv0QVeYT5B3l1bhAiakkTWpV2dUzz4L/G6mzjuQk=; b=OuorBqHnX9URjIKABIWBrr3rvTvy3Fcrc7hycv41a+zcq5x7CBebpaSeP6tVMKzPKF 4EKnvsD2b0OCJ8p5K5ooK8BAJEQpareK6Xu+qlFgh5OEztlv10soeBMJXgWt04kxVW/u lvA0VA1rjJuKu1IvKyoVFIKBAy8uLUdfQmdet3wdlccvR/efETVF++RnO3expVZFuqOK v80oDCm5qCB7QFPdG+Q2pPjcWUu1c9ea5wf3h1jNqqN3h9xBf/zmJnPGH/yugjwZkzH8 Uaw9EovpzXQVOckZ0gI79kVO4lQg5daQR8fqEYFFpumC/V99Dk+GCewB/JIzhkg5Kq81 V6Qg== X-Gm-Message-State: AOAM530x06aJMarWMCCboXzXxgNYUGW0j23BExJZbwo916HysdZ6xVWr DWqDuaUooEffoda0VoAhUaNrFA== X-Google-Smtp-Source: ABdhPJwF9zI7bRfIB36U3AUQm75x0SFlBSbcOtcBYlJDo+lGaq5lVXU3DLbC/9xQTVmQz90WttCvbw== X-Received: by 2002:aa7:8a15:0:b0:44c:8cae:d311 with SMTP id m21-20020aa78a15000000b0044c8caed311mr2886847pfa.52.1633470854471; Tue, 05 Oct 2021 14:54:14 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id t13sm2974043pjg.25.2021.10.05.14.54.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Oct 2021 14:54:14 -0700 (PDT) Date: Tue, 5 Oct 2021 14:54:13 -0700 From: Kees Cook To: Matthew Wilcox Cc: linux-mm@kvack.org, Thomas Gleixner Subject: Re: [PATCH 1/3] mm/usercopy: Check kmap addresses properly Message-ID: <202110051453.A2002FE@keescook> References: <20211004224224.4137992-1-willy@infradead.org> <20211004224224.4137992-2-willy@infradead.org> <202110051422.3E52FBDE18@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 87611103A712 X-Stat-Signature: x1it1oruqusmrzfmzu6tb5nnsup7o7kn Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Qold4IGQ; spf=pass (imf13.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.182 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-HE-Tag: 1633470855-792504 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 Tue, Oct 05, 2021 at 10:43:13PM +0100, Matthew Wilcox wrote: > On Tue, Oct 05, 2021 at 02:23:09PM -0700, Kees Cook wrote: > > > + if (is_kmap_addr(ptr)) { > > > + unsigned long page_end = (unsigned long)ptr | (PAGE_SIZE - 1); > > > + > > > + if ((unsigned long)ptr + n - 1 > page_end) > > > + usercopy_abort("kmap", NULL, to_user, 0, n); > > > > It's likely not worth getting an offset here, but "0" above could be > > something like "ptr - PKMAP_ADDR(0)". > > Mmm. page_offset(ptr) should do the trick, no? Ah yeah, that'd be good! -Kees > > > Either way: > > > > Acked-by: Kees Cook > > > > Thanks! > > > > -Kees > > > > > + return; > > > + } > > > + > > > + page = virt_to_head_page(ptr); > > > > > > if (PageSlab(page)) { > > > /* Check slab allocator for flags and size. */ > > > -- > > > 2.32.0 > > > > > > > -- > > Kees Cook -- Kees Cook