Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp329172yba; Sat, 20 Apr 2019 03:33:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqypmnxatOWKhVWt0PCpY0CiSMb87Yv/7dlPw5chNQ6IZzSASiglBhizvP56S/XcOs5yW31h X-Received: by 2002:a17:902:d24:: with SMTP id 33mr8930985plu.246.1555756392297; Sat, 20 Apr 2019 03:33:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555756392; cv=none; d=google.com; s=arc-20160816; b=nFPokM5J4a8rdHK0IetB6LMvCu+yBEW3GV+FGN3Ujc8oQvrEI8y0Q0autYiECicWu7 U+7c6XUKN7CtND+I6ILxvtApCynZo6kqiL50VOt57nxZ0HZSI61LKwoxJqM0HFtv/QyF lG63vl2EYJPn627fmFwczvjvCDk2/kqWXdAk6ZoR+RgZbmmyVdrFkr8FTyu4U1SUt/cb xFLkjE08eIbUfQDzFRTpmFZzVEX6okjwMXr5dcbI0+5wjHrZq+3fOL1lMiGzQDdCqjM3 LOF7RmpGMAUcTC5NZPIu8lLiTHjaYEvF3v7EZOmdIISUt0w+pPwheTWMoA5PgIcxxcFk GvjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from; bh=hiHgGeq7y6M6RXm8tzukqrUNVKb/GFeQ+zvZXxY4fjM=; b=DWY5JNpv+FdatpQlFzxC9jN+6Pxt1y9QJt0uTeWPMPqBW9j+l46FF/BGWVlBCJHhRS Z2EnUUlZjQjlC9q2/TACVrCCVP7d1LAx+bSft09NZ5NBOo5AnJXRdnNyGQLvIRe6eOgp rI6xAgBWxL/SYdoT/UohCOY9uvJh4vSVuW8uapThczVAVnG4cj0Ztmko6R3F02p4g0/I 9siCNCcABi22Bygt3iYdzaPzHzF14GeZpU/YHTvVLkZfZDwUfGywm+zdh3VtYK+v+tXV HHufSH1vmrp9xxItVUbr8uHMTrU2z9R0hksZocxutQt+/dtRmyfV0W9JXN7UQvbNV1W+ 8iFw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k3si8076232pfc.91.2019.04.20.03.32.56; Sat, 20 Apr 2019 03:33:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727838AbfDTKbe (ORCPT + 99 others); Sat, 20 Apr 2019 06:31:34 -0400 Received: from bilbo.ozlabs.org ([203.11.71.1]:59405 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725920AbfDTKbe (ORCPT ); Sat, 20 Apr 2019 06:31:34 -0400 Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 44mTf91SR8z9s70; Sat, 20 Apr 2019 20:31:28 +1000 (AEST) From: Michael Ellerman To: Thomas Gleixner , Dave Hansen Cc: LKML , rguenther@suse.de, mhocko@suse.com, vbabka@suse.cz, luto@amacapital.net, x86@kernel.org, Andrew Morton , linux-mm@kvack.org, stable@vger.kernel.org, Laurent Dufour Subject: Re: [PATCH] x86/mpx: fix recursive munmap() corruption In-Reply-To: References: <20190401141549.3F4721FE@viggo.jf.intel.com> Date: Sat, 20 Apr 2019 20:31:27 +1000 Message-ID: <87d0lht1c0.fsf@concordia.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thomas Gleixner writes: > On Mon, 1 Apr 2019, Dave Hansen wrote: >> diff -puN mm/mmap.c~mpx-rss-pass-no-vma mm/mmap.c >> --- a/mm/mmap.c~mpx-rss-pass-no-vma 2019-04-01 06:56:53.409411123 -0700 >> +++ b/mm/mmap.c 2019-04-01 06:56:53.423411123 -0700 >> @@ -2731,9 +2731,17 @@ int __do_munmap(struct mm_struct *mm, un >> return -EINVAL; >> >> len = PAGE_ALIGN(len); >> + end = start + len; >> if (len == 0) >> return -EINVAL; >> >> + /* >> + * arch_unmap() might do unmaps itself. It must be called >> + * and finish any rbtree manipulation before this code >> + * runs and also starts to manipulate the rbtree. >> + */ >> + arch_unmap(mm, start, end); > > ... > >> -static inline void arch_unmap(struct mm_struct *mm, struct vm_area_struct *vma, >> - unsigned long start, unsigned long end) >> +static inline void arch_unmap(struct mm_struct *mm, unsigned long start, >> + unsigned long end) > > While you fixed up the asm-generic thing, this breaks arch/um and > arch/unicorn32. For those the fixup is trivial by removing the vma > argument. > > But itt also breaks powerpc and there I'm not sure whether moving > arch_unmap() to the beginning of __do_munmap() is safe. Micheal??? I don't know for sure but I think it should be fine. That code is just there to handle CRIU unmapping/remapping the VDSO. So that either needs to happen while the process is stopped or it needs to handle races anyway, so I don't see how the placement within the unmap path should matter. > Aside of that the powerpc variant looks suspicious: > > static inline void arch_unmap(struct mm_struct *mm, > unsigned long start, unsigned long end) > { > if (start <= mm->context.vdso_base && mm->context.vdso_base < end) > mm->context.vdso_base = 0; > } > > Shouldn't that be: > > if (start >= mm->context.vdso_base && mm->context.vdso_base < end) > > Hmm? Yeah looks pretty suspicious. I'll follow-up with Laurent who wrote it. Thanks for spotting it! cheers