Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp3306426imd; Mon, 29 Oct 2018 05:14:25 -0700 (PDT) X-Google-Smtp-Source: AJdET5fdaLj0vqKJuLf9E7S2Eidwaqhdq3ORXO2EDr5/p1bW1HVzZsJs2cQsfM1PSZtRg5d/poMF X-Received: by 2002:a17:902:bb88:: with SMTP id m8-v6mr13755101pls.120.1540815265948; Mon, 29 Oct 2018 05:14:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540815265; cv=none; d=google.com; s=arc-20160816; b=OL5Z3hWNKh6vuPFno+Namyv1e16YoCUOLI41TzZZ/Gf1T/I9W8G0bJT2dsag/6T5x9 2lsP4YjkHhgIL5TJbUbBs12+Mj2b3jQqXGBtMprxtzhanECjeP3/jVuI6EvavsqnZJYn a/vOGe2HvR1emlVBsX27+S8SzczLOCrBGixZ1zVbeP+TIcDT0OZWfNNJa9mw39i62JFe ZhxXSpJDk4oGvvJkxI5Qr6mOTRGh/9m4TdDVsUAzwt+QgdZopX4BLehTKrV68bDv6JbO 94ELmoC8OH7qnX8mVBs+AwG6CYiGJTnssTpO6WbmKvxnvOGcs+wngxS3TT06DtYdmfS6 9K4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature; bh=LkSym710dhbXJ+qA0PXYOCzvXqoMmpZWVpKKwzIQAeI=; b=o9MSjnV8Q5t7aBMpLjFyiwWOZ5byUULBmu/4tG1gOx5NRahZcXxbhjgdM6hR535lIJ gWdtyhKTBfPX3gZn4rTS99eZCB8n24C/5Muy3Pq9FX6OzDWlt5RyJGINk+XqeS9T1/8r Y8GFfDS2HnG6zsDuSIiFiy0ag4DeYvKsEV22/ta6m4mOZeF0P4TFs4lI9CgLEIpCaLYu IC9VD+F1CONRQjrr/MaIvD/L8ACjf4F2jzKsucdnqM5fxn79tCQASGQb8Fnr6ymWHAJh lVAhW8Zl6jX6COvqhPyNeb7qdoGXthmxH7AXPhdNB4ihkMjkZF27QYIheoExaDCp/uZk 4ihQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=tPsRGMN5; 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 t76-v6si20234504pgc.485.2018.10.29.05.14.05; Mon, 29 Oct 2018 05:14:25 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=tPsRGMN5; 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 S1729288AbeJ2U7u (ORCPT + 99 others); Mon, 29 Oct 2018 16:59:50 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:33274 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729227AbeJ2U7u (ORCPT ); Mon, 29 Oct 2018 16:59:50 -0400 Received: by mail-qt1-f195.google.com with SMTP id i15-v6so8849088qtr.0 for ; Mon, 29 Oct 2018 05:11:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=LkSym710dhbXJ+qA0PXYOCzvXqoMmpZWVpKKwzIQAeI=; b=tPsRGMN5xZqQdMbvIkUhvjQ96uX71je3k4oSLF4xX83wsL+twsvlIijwQSMwmffXPQ /FRBfKBxcRsZkvbX1UoP05ZgNZWhopgzLgY6K33+bby8lybYWM4b4750CiZciiLMPJby O2pjlZrQD5mBH2RcQo2UNR/ytBaL8j1ndnjXJKjy8zcQZnkE9dFz08rgKpspOQeShQ7N xKTAhRKfqkxMO+aacA5s7g9Fh+ZXqgPhz4NPxxQFpTsEBpdBUFNlI8Zno5WnfNuEgEMx BVZxblbzxwJ3wQsdRYyev11CptEqdsCzKvCnXgObdbrgi1iIn40ReVlMIXDB4LPdFjGH lLsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=LkSym710dhbXJ+qA0PXYOCzvXqoMmpZWVpKKwzIQAeI=; b=gydbEbXTErN2NPQgKEzAYYdUKZHhqMZUqIo7M4nSqMWpcq+YUZuDAecKPGNPTwE9VX MnXLweB9Tz3fum/py2Hd8COudMp7LnnpvaMb0hEo0xnHouOKGqMM79xhYL7wIpgkla34 Hhcgb7/Drlr0OgtjMDWq9gkzxHY/UXLgxzHJuKuMqw6Uknzu+QgV+/kyK19ZLoK2LRMU xQXU2qWIp83a6nRJynMDwQt2YqIQyij1ASzMJVd6bVHnCeazqP6theZh3dfIej4ucFtj YQIMbj8ZEwu+auyho4dKhjZX/PMCaWXjCZrF1FgLqFud24sYuANMgpCHMLXQi2beZbkw BOeg== X-Gm-Message-State: AGRZ1gKWj2G45Dwo7vktf9eaooR9uXzItvRygiju/oRSkI3C5wXSzSli q3gDxF7Gk0OeZgNroaimONDpfhcSZvjMa4fxw9s= X-Received: by 2002:a0c:8d4b:: with SMTP id s11mr12538580qvb.161.1540815084717; Mon, 29 Oct 2018 05:11:24 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a0c:988d:0:0:0:0:0 with HTTP; Mon, 29 Oct 2018 05:11:24 -0700 (PDT) In-Reply-To: <20181029120434.GA15446@arm.com> References: <20181015111600.5479-1-anders.roxell@linaro.org> <20181029120434.GA15446@arm.com> From: Arnd Bergmann Date: Mon, 29 Oct 2018 13:11:24 +0100 X-Google-Sender-Auth: UFEws_gRvEFSJ_13WIzOuGkjXO4 Message-ID: Subject: Re: [PATCH] arm64: kprobe: make page to RO mode when allocate it To: Will Deacon Cc: Anders Roxell , catalin.marinas@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Ard Biesheuvel , Laura Abbott Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/29/18, Will Deacon wrote: > On Mon, Oct 15, 2018 at 01:16:00PM +0200, Anders Roxell wrote: >> -static int __kprobes patch_text(kprobe_opcode_t *addr, u32 opcode) >> +void *alloc_insn_page(void) >> { >> - void *addrs[1]; >> - u32 insns[1]; >> + void *page; >> >> - addrs[0] = (void *)addr; >> - insns[0] = (u32)opcode; >> + page = vmalloc_exec(PAGE_SIZE); >> + if (page) >> + set_memory_ro((unsigned long)page & PAGE_MASK, 1); > > This looks a bit strange to me -- you're allocating PAGE_SIZE bytes so > that we can adjust the permissions, yet we can't guarantee that page is > actually page-aligned and therefore end up explicitly masking down. > > In which case allocating an entire page isn't actually helping us, and > we could end up racing with somebody else changing permission on the > same page afaict. > > I think we need to ensure we really have an entire page, perhaps using > vmap() instead? Or have I missed some subtle detail here? I'm fairly sure that vmalloc() and vmalloc_exec() is guaranteed to be page aligned everywhere. The documentation is a bit vague here, but I'm still confident enough that we can make that assumption based on /** * vmalloc_exec - allocate virtually contiguous, executable memory * @size: allocation size * * Kernel-internal function to allocate enough pages to cover @size * the page level allocator and map them into contiguous and * executable kernel virtual space. * * For tight control over page level allocator and protection flags * use __vmalloc() instead. */ void *vmalloc_exec(unsigned long size) Arnd