From patchwork Tue Sep 20 15:56:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 9341973 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 23761607EE for ; Tue, 20 Sep 2016 15:56:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1662429658 for ; Tue, 20 Sep 2016 15:56:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AEC2298D0; Tue, 20 Sep 2016 15:56:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 19CD229658 for ; Tue, 20 Sep 2016 15:56:56 +0000 (UTC) Received: (qmail 29947 invoked by uid 550); 20 Sep 2016 15:56:53 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: kernel-hardening@lists.openwall.com Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 29927 invoked from network); 20 Sep 2016 15:56:52 -0000 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=CLzHVOaqCdbpvpDF0ow0oob7nMJDzVMO5koykHun4ak=; b=JbY99ZzqnPYoqio7u6ECyLXPLQ/6pf7PCzUE8XzfsVaStMXBzAqCdTR5C7CL2a7HDs k73h+8pez3Ki2m5cL3JGBKGpFsoJSdpPNcbmV0SdbJEiQVJnzHl6pQhyDq1x8EITBx0K Zuh9so702CIZ9nzS8R76nFI8bMgUt0LZCAj9V055xthCxmhCjOhqeuaZR0cgOO7y1WcV basFdbn1wKXVGUkp60zLDg4y8RJMGEg0Zj1xh4Ff941bn0h1WOLZbKoctm/EwLBav5NP TXy0WTVgajMNp2dNQH2xPUWBZhIPVJ0KqVloDY+zYavhZ21ujqyV+r0lLG7zdraF/k8Q tmfw== X-Gm-Message-State: AE9vXwNMuVNCxMaGGnT5dpZIOG3F7yIrrwSS9Vt2BpRzMFFE5T48khU4SjgR00kJjZmeDdfk X-Received: by 10.13.248.129 with SMTP id i123mr29814137ywf.182.1474387000752; Tue, 20 Sep 2016 08:56:40 -0700 (PDT) From: Laura Abbott To: Kees Cook Cc: Laura Abbott , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com Date: Tue, 20 Sep 2016 08:56:36 -0700 Message-Id: <1474386996-16049-1-git-send-email-labbott@redhat.com> X-Mailer: git-send-email 2.7.4 Subject: [kernel-hardening] [PATCH] mm: usercopy: Check for module addresses X-Virus-Scanned: ClamAV using ClamSMTP While running a compile on arm64, I hit a memory exposure usercopy: kernel memory exposure attempt detected from fffffc0000f3b1a8 (buffer_head) (1 bytes) ------------[ cut here ]------------ kernel BUG at mm/usercopy.c:75! Internal error: Oops - BUG: 0 [#1] SMP Modules linked in: ip6t_rpfilter ip6t_REJECT nf_reject_ipv6 xt_conntrack ip_set nfnetlink ebtable_broute bridge stp llc ebtable_nat ip6table_security ip6table_raw ip6table_nat nf_conntrack_ipv6 nf_defrag_ipv6 nf_nat_ipv6 ip6table_mangle iptable_security iptable_raw iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack iptable_mangle ebtable_filter ebtables ip6table_filter ip6_tables vfat fat xgene_edac xgene_enet edac_core i2c_xgene_slimpro i2c_core at803x realtek xgene_dma mdio_xgene gpio_dwapb gpio_xgene_sb xgene_rng mailbox_xgene_slimpro nfsd auth_rpcgss nfs_acl lockd grace sunrpc xfs libcrc32c sdhci_of_arasan sdhci_pltfm sdhci mmc_core xhci_plat_hcd gpio_keys CPU: 0 PID: 19744 Comm: updatedb Tainted: G W 4.8.0-rc3-threadinfo+ #1 Hardware name: AppliedMicro X-Gene Mustang Board/X-Gene Mustang Board, BIOS 3.06.12 Aug 12 2016 task: fffffe03df944c00 task.stack: fffffe00d128c000 PC is at __check_object_size+0x70/0x3f0 LR is at __check_object_size+0x70/0x3f0 ... [] __check_object_size+0x70/0x3f0 [] filldir64+0x158/0x1a0 [] __fat_readdir+0x4a0/0x558 [fat] [] fat_readdir+0x34/0x40 [fat] [] iterate_dir+0x190/0x1e0 [] SyS_getdents64+0x88/0x120 [] el0_svc_naked+0x24/0x28 fffffc0000f3b1a8 is a module address. Modules may have compiled in strings which could get copied to userspace. In this instance, it looks like "." which matches with a size of 1 byte. Extend the is_vmalloc_addr check to be is_vmalloc_or_module_addr to cover all possible cases. Signed-off-by: Laura Abbott --- Longer term, it would be good to expand the check for to regions like regular kernel memory. --- mm/usercopy.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/usercopy.c b/mm/usercopy.c index 8ebae91..d8b5bd3 100644 --- a/mm/usercopy.c +++ b/mm/usercopy.c @@ -145,8 +145,11 @@ static inline const char *check_heap_object(const void *ptr, unsigned long n, * Some architectures (arm64) return true for virt_addr_valid() on * vmalloced addresses. Work around this by checking for vmalloc * first. + * + * We also need to check for module addresses explicitly since we + * may copy static data from modules to userspace */ - if (is_vmalloc_addr(ptr)) + if (is_vmalloc_or_module_addr(ptr)) return NULL; if (!virt_addr_valid(ptr))