From patchwork Sun Jun 12 21:32:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 12878842 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8087DC433EF for ; Sun, 12 Jun 2022 21:32:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D8AE56B0154; Sun, 12 Jun 2022 17:32:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D3B1A6B0157; Sun, 12 Jun 2022 17:32:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C01DD6B0158; Sun, 12 Jun 2022 17:32:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B02456B0154 for ; Sun, 12 Jun 2022 17:32:34 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 806FD349FD for ; Sun, 12 Jun 2022 21:32:34 +0000 (UTC) X-FDA: 79570883028.23.9C29D7F Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf31.hostedemail.com (Postfix) with ESMTP id 9664F2009C for ; Sun, 12 Jun 2022 21:32:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=KF4owYCbPISYV5a61DiGRvGs/L1LMsz9ReyZ7eXT5t8=; b=geEs3gAVKXk3eNcQdArpYi2DVd f/MN4q94FG7FHdgrWVmDI4vEtNGBpS1vD/DP2rHs7ji3PrgfGGHOWvn8A3AAmpRzatm8leS4fNMaR Fs6S3luOZoQnLu1wdgThCd5i4g41xF0vblXF68HK3PGR3NF5mHXwdGlK8f7j8EYhpBEMYEy9oRHEH qlEW7b8tnYQ0rBpT67IXfWPu99LTz+lOBZmsIyf5LrvwXzKFSHCbS4hUlucLJWK2Wrj8/2TQSpg3W i9qz6yiljtaOFgTf83pXjguAzUIl6miPCNqPkGAOUJitBDthtLjXjcCzOkxJg685Cs7EdPJSyQkRX IVlGdg9w==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1o0VC9-00GHpy-EN; Sun, 12 Jun 2022 21:32:29 +0000 From: "Matthew Wilcox (Oracle)" To: Kees Cook Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, Uladzislau Rezki , Zorro Lang , linux-xfs@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH 2/3] usercopy: Cast pointer to an integer once Date: Sun, 12 Jun 2022 22:32:26 +0100 Message-Id: <20220612213227.3881769-3-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220612213227.3881769-1-willy@infradead.org> References: <20220612213227.3881769-1-willy@infradead.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655069554; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=KF4owYCbPISYV5a61DiGRvGs/L1LMsz9ReyZ7eXT5t8=; b=sb5KitDAFjJpexETOaOo+ony2nrwWW9p6BGXHk+w2xyO8So7U3qlVo1G7ulUR7w0QII0kx YRG3nu6iyCZ0PqQ11UgH1MKddy752wX8q+aolmGFJG+GzGbgF6An8iFcChk7UdQA2fJBir JkSjvMLP4MFW/gYK8C1HlFtxP2hsH0w= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655069554; a=rsa-sha256; cv=none; b=56LRTpNPFU+7f+Uw87ECaJ4xZ3ZdZCIoIVEh3axEwhinvNhfCdLbsfDOPFghP5qcyfc2Bg U9JAqK84uOB7mf0BCfc+OtvVXq5XgfnHE2DUEj+Jl9PSMr5/wPIcF4aCwIYjoFESilZATA 8zwwk4QF9pWH2tPu+l182FM+IWm64Gg= ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=geEs3gAV; dmarc=none; spf=none (imf31.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-Rspam-User: Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=geEs3gAV; dmarc=none; spf=none (imf31.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-Rspamd-Server: rspam03 X-Stat-Signature: ksboe8yokws3rnq61138kznacbg7h4h7 X-Rspamd-Queue-Id: 9664F2009C X-HE-Tag: 1655069553-890885 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: Get rid of a lot of annoying casts by setting 'addr' once at the top of the function. Signed-off-by: Matthew Wilcox (Oracle) --- mm/usercopy.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mm/usercopy.c b/mm/usercopy.c index fdd1bed3b90a..31deee7dd2f5 100644 --- a/mm/usercopy.c +++ b/mm/usercopy.c @@ -161,19 +161,20 @@ static inline void check_bogus_address(const unsigned long ptr, unsigned long n, static inline void check_heap_object(const void *ptr, unsigned long n, bool to_user) { + uintptr_t addr = (uintptr_t)ptr; struct folio *folio; if (is_kmap_addr(ptr)) { - unsigned long page_end = (unsigned long)ptr | (PAGE_SIZE - 1); + unsigned long page_end = addr | (PAGE_SIZE - 1); - if ((unsigned long)ptr + n - 1 > page_end) + if (addr + n - 1 > page_end) usercopy_abort("kmap", NULL, to_user, offset_in_page(ptr), n); return; } if (is_vmalloc_addr(ptr)) { - struct vmap_area *area = find_vmap_area((unsigned long)ptr); + struct vmap_area *area = find_vmap_area(addr); unsigned long offset; if (!area) { @@ -183,8 +184,8 @@ static inline void check_heap_object(const void *ptr, unsigned long n, /* XXX: We should also abort for free vmap_areas */ - offset = (unsigned long)ptr - area->va_start; - if ((unsigned long)ptr + n > area->va_end) + offset = addr - area->va_start; + if (addr + n > area->va_end) usercopy_abort("vmalloc", NULL, to_user, offset, n); return; }