Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7322132rwb; Mon, 12 Dec 2022 13:06:31 -0800 (PST) X-Google-Smtp-Source: AA0mqf5cwAJJO/hxnvtTXw1bf1cFuXPc2+BiSsxqPjqDNmQiIu77UAd/efpeH2o1Hr38zAp9e/MV X-Received: by 2002:a05:6402:1491:b0:46c:e615:9f61 with SMTP id e17-20020a056402149100b0046ce6159f61mr15714697edv.25.1670879191429; Mon, 12 Dec 2022 13:06:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670879191; cv=none; d=google.com; s=arc-20160816; b=nmaE1OwLPPwRYDupUPfbelWDqQiskyOqauU5F4iE0HIt4zWseQsGZyg+Vl8BaIVojB ly9/jXOZ1oCxHBii1PS+H+gdQ4yKUskGiFxx5r59uLF+F4T9v9WFQ4s95N5lrx+OcvFP BtLcVUa821/Dxxm3k1T6S07xm/CdmZ0da+CtiMTAWeGOdeQHI+hMCE9IExcE9yPy62AO X6InPxt8Ef4IL6LEJlnwMVy0J1YjyeJuRIsT+OCTmpx4Tn8m/UT2A2bOIcwU/oWse7Lk e+o0eRdKI9MQhwHskNXOQbEj5CWmplsstx7UOFm0Di2Fhzxjoj3QZUQWn5WxFNmK346m WfDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=+33heWZqPNvN/OOyLci+aYXHO8pTl7ySUh12yfzj1hI=; b=IY3fGhPW0dBOerGB6UGALE2T0o2nzEP3/fpKRTZ/PkmkGYMOcBLoYTi0Bdv78P5fek NjVUihHgMBTHrBt2NsVUHhO7KHZ8XlIiHv8SXmFWmyakxNaYsnVDOqg+FQKMeZFQKwGe zmjPUnp3x7u90FBfonLOPESCyw3xcLXDCG+7dIFQcpiOKwSnF/HOr5r1KJPusLktiTXD YWBKplFT9R2/vnMp3xqd5tz0WEowAtWyuuMlllLoBsUcoEecoCpyqzrDtYTzFHe0wPxQ J1QeFFFcOcVjger0Wr+A+j/4hr8RdVTQta+dHFwrmnIPVqBXYf7JoN2CuYGDnDyJPBmv qkKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=ROzf0OEV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j24-20020aa7ca58000000b00469f14100ecsi7646569edt.375.2022.12.12.13.06.13; Mon, 12 Dec 2022 13:06:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=ROzf0OEV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233143AbiLLVCi (ORCPT + 74 others); Mon, 12 Dec 2022 16:02:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233182AbiLLVCL (ORCPT ); Mon, 12 Dec 2022 16:02:11 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20CDB18E3F; Mon, 12 Dec 2022 13:01:40 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9F32B6122B; Mon, 12 Dec 2022 21:01:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B883C433EF; Mon, 12 Dec 2022 21:01:37 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="ROzf0OEV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1670878895; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+33heWZqPNvN/OOyLci+aYXHO8pTl7ySUh12yfzj1hI=; b=ROzf0OEVcwV9kZSenrrYUtosBdsEhtxY7C5PILTab3NuW9wgoBfEK7sg5PUW//W6yifT10 ENmm15ZqndAQutSnhGJelFw/OERj0DcstMOjf1WGns0U/WRd3zssrruw/4aQoaNXtR6aB3 zGr3RiiFUgrPUH0iNcctwVACAJvXiS4= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id b60ecb78 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 12 Dec 2022 21:01:35 +0000 (UTC) Date: Mon, 12 Dec 2022 14:01:33 -0700 From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, patches@lists.linux.dev, tglx@linutronix.de Cc: linux-crypto@vger.kernel.org, linux-api@vger.kernel.org, x86@kernel.org, Greg Kroah-Hartman , Adhemerval Zanella Netto , Carlos O'Donell , Florian Weimer , Arnd Bergmann , Jann Horn , Christian Brauner , linux-mm@kvack.org Subject: Re: [PATCH RFC v12 2/6] x86: mm: Skip faulting instruction for VM_DROPPABLE faults Message-ID: References: <20221212185347.1286824-1-Jason@zx2c4.com> <20221212185347.1286824-3-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20221212185347.1286824-3-Jason@zx2c4.com> X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 12, 2022 at 11:53:43AM -0700, Jason A. Donenfeld wrote: > + if (fault & VM_FAULT_SKIP_INSN) { > + u8 insn_buf[MAX_INSN_SIZE]; > + struct insn insn; > + size_t len; > + > + len = sizeof(insn_buf) - copy_from_user(insn_buf, (void *)regs->ip, sizeof(insn_buf)); > + if (!len) > + return; > + > + if (insn_decode(&insn, insn_buf, len, in_32bit_syscall() ? INSN_MODE_32 : INSN_MODE_64) < 0) > + return; > + > + regs->ip += insn.length; > + return; > + } I just found umip.c, which does basically the same thing, but does it correctly. For v+1, the above snippet will instead do this: if (fault & VM_FAULT_SKIP_INSN) { u8 buf[MAX_INSN_SIZE]; struct insn insn; int nr_copied; nr_copied = insn_fetch_from_user(regs, buf); if (nr_copied <= 0) return; if (!insn_decode_from_regs(&insn, regs, buf, nr_copied)) return; regs->ip += insn.length; return; } Same thing, but those helpers do correct inspection of the environment and registers. Also, seeing this already being done in umip.c is heartening that the approach here isn't overly insane. Jason