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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 401C4C43334 for ; Sun, 12 Jun 2022 13:03:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DD036B01F9; Sun, 12 Jun 2022 09:03:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 465126B01FA; Sun, 12 Jun 2022 09:03:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2DE4D6B01FB; Sun, 12 Jun 2022 09:03:25 -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 192FB6B01F9 for ; Sun, 12 Jun 2022 09:03:25 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DC58934ABE for ; Sun, 12 Jun 2022 13:03:24 +0000 (UTC) X-FDA: 79569599928.20.C8CCC9C Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) by imf29.hostedemail.com (Postfix) with ESMTP id 7C230120003 for ; Sun, 12 Jun 2022 13:03:24 +0000 (UTC) Received: by mail-lf1-f49.google.com with SMTP id a29so5099155lfk.2 for ; Sun, 12 Jun 2022 06:03:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=YTsB0N3qWfzpCuWe8xUMKoFVyRm+YxRVrS5Z4FIpVVM=; b=AsSwvwNxL3KeUSJBcoZ1iIcJZEbYruf9NSXjmaXfcvuJyayYlkSFFLGoZeVq1oKbIV XaKFFMgzUChyJSjOYc4cV+T+Fq2TnxHZNYbunfmIKKsC0LbSyE+xfHHcQRgFcSgK11oz eePYpL3UNGYvOHZWbnkvec1YWEtms7M4wVIbaND/rK9DabSHc/ePrKzHf05lYkv3Kpje d7AARJjjV+tK+qtU28DOaQ4d0/hfJQa0G4YsZcux5eKLf1g5t08/msVAQFRppSHDGaoD rboxzHmavmc760MOPfbsNwK0UvEdktGWEgkSdHfJfDGJzlZY4/xb7rEreVlv2gMOokJk t2Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=YTsB0N3qWfzpCuWe8xUMKoFVyRm+YxRVrS5Z4FIpVVM=; b=TkWa1ADj0JqmjvsRIeCzmq5iuK9kUo3NrqVgPEQ7a29XnFDsoU2TT9LI2Vm6WUcXm/ a60vNO/6U4hsAdRQW8mvmePzbgQKMUdi0jmqA+I1kXrNwPLa/aY6Wifl5Fkeb3bRXNrI Q7JL9xAhOO5zmgvZH0dgyV4Zm6W5NWh1DPbshJMJjQlSmNv0mweVHJ/R9AzG/emYHwV6 PxR3YtSOs2yyXiMMngz19VK85/NuUYexRiXvvEG3/XgOZgIfZJQgU2Si5tb3sB+YFb+d wuOayG6wvpsVWqNq8ouJSQqq9q3dE8qOpCq4eQJruJvbm/ZgEvpuWrAW8gRpug7TN9YY FMpA== X-Gm-Message-State: AOAM532o27n00ZOs0pk9rk2eZ+z3f08bx2N23bnva5H7VtP7GlwmDx1U 3Tt75bxAWvkvWSUVBjen1jI= X-Google-Smtp-Source: ABdhPJxqBZF44drPTOlVrkQ14816GxopWXiCGJdlxVakknAiNSZNINLfaOvEAx+0CqgPBpKB0XTklw== X-Received: by 2002:a05:6512:308b:b0:479:3986:1d5c with SMTP id z11-20020a056512308b00b0047939861d5cmr21705756lfd.99.1655039002668; Sun, 12 Jun 2022 06:03:22 -0700 (PDT) Received: from pc638.lan ([155.137.26.201]) by smtp.gmail.com with ESMTPSA id a15-20020a056512200f00b0047255d210f4sm607717lfb.35.2022.06.12.06.03.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 06:03:21 -0700 (PDT) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Sun, 12 Jun 2022 15:03:20 +0200 To: Matthew Wilcox Cc: Zorro Lang , Alexander Gordeev , bugzilla-daemon@kernel.org, linux-s390@vger.kernel.org, linux-xfs@vger.kernel.org, Andrew Morton , linux-mm@kvack.org, Uladzislau Rezki , Kees Cook Subject: Re: [Bug 216073] New: [s390x] kernel BUG at mm/usercopy.c:101! usercopy: Kernel memory exposure attempt detected from vmalloc 'n o area' (offset 0, size 1)! Message-ID: References: <20220606151312.6a9d098c85ed060d36519600@linux-foundation.org> <20220608021922.n2izu7n4yoadknkx@zlang-mailbox> <20220612044230.murerhsa765akogj@zlang-mailbox> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655039004; a=rsa-sha256; cv=none; b=ITPfW+99Eg15C6hiM5OJueI1xMpWhvt3i+KFJJZdwGMxC6+kgNxoLAWnm+rsU6662Vk/A3 ng7NmIbSf3KaYfFy/MRoH9DM74dSrvKEpfTEa/Y7uPTuIuNc7EDfPh1N3QJYJyTOsn1n6d Y7Rf4ZVJvSAWR28+ZAMDhDBgB0LQ468= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655039004; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YTsB0N3qWfzpCuWe8xUMKoFVyRm+YxRVrS5Z4FIpVVM=; b=B+nKWoG50n1SA3ozw6fBH17vocHMjoETo6q71U5C7GFkJAoQg68SPNdZE9PKc2GSwdHN3r QIBrdmsw6HX9NN37HNTy6R9P8WhLlJdEa3sn424nt0iOsUpySFLJBsxxkm10ffCvmmQe+K uqD0AtAOXeF+xAEupCBa9Pod2N153YM= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=AsSwvwNx; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.49 as permitted sender) smtp.mailfrom=urezki@gmail.com Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=AsSwvwNx; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.49 as permitted sender) smtp.mailfrom=urezki@gmail.com X-Stat-Signature: utea6bg8y1otykxopa6ifbto58zopy8m X-Rspamd-Queue-Id: 7C230120003 X-Rspamd-Server: rspam12 X-Rspam-User: X-HE-Tag: 1655039004-739204 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 Sun, Jun 12, 2022 at 12:42:30PM +0800, Zorro Lang wrote: > > Looks likt it's not a s390x specific bug, I just hit this issue once (not 100% > > reproducible) on aarch64 with linux v5.19.0-rc1+ [1]. So back to cc linux-mm > > to get more review. > > > > [1] > > [ 980.200947] usercopy: Kernel memory exposure attempt detected from vmalloc 'no area' (offset 0, size 1)! > > if (is_vmalloc_addr(ptr)) { > struct vm_struct *area = find_vm_area(ptr); > if (!area) { > usercopy_abort("vmalloc", "no area", to_user, 0, n); > > Oh. Looks like XFS uses vm_map_ram() and vm_map_ram() doesn't allocate > a vm_struct. > > Ulad, how does this look to you? > It looks like a correct way to me :) XFS uses per-cpu-vm_map_ram()-vm_unmap_ram() API which do not allocate "vm_struct" because it is not needed. > > diff --git a/mm/usercopy.c b/mm/usercopy.c > index baeacc735b83..6bc2a1407c59 100644 > --- a/mm/usercopy.c > +++ b/mm/usercopy.c > @@ -173,7 +173,7 @@ static inline void check_heap_object(const void *ptr, unsigned long n, > } > > if (is_vmalloc_addr(ptr)) { > - struct vm_struct *area = find_vm_area(ptr); > + struct vmap_area *area = find_vmap_area((unsigned long)ptr); > unsigned long offset; > > if (!area) { > @@ -181,8 +181,9 @@ static inline void check_heap_object(const void *ptr, unsigned long n, > return; > } > > - offset = ptr - area->addr; > - if (offset + n > get_vm_area_size(area)) > + /* XXX: We should also abort for free vmap_areas */ > + offset = (unsigned long)ptr - area->va_start; > I was a bit confused about "offset" and why it is needed here. It is always zero. So we can get rid of it to make it less confused. From the other hand a zero offset contributes to nothing. > > + if (offset + n >= area->va_end) > I think it is a bit wrong. As i see it, "n" is a size and what we would like to do here is boundary check: if (n > va_size(area)) usercopy_abort("vmalloc", NULL, to_user, 0, n); -- Uladzislau Rezki