Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753074AbdDEDpm (ORCPT ); Tue, 4 Apr 2017 23:45:42 -0400 Received: from mail-qk0-f171.google.com ([209.85.220.171]:34549 "EHLO mail-qk0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752792AbdDEDpk (ORCPT ); Tue, 4 Apr 2017 23:45:40 -0400 Date: Tue, 4 Apr 2017 21:45:36 -0600 From: Tycho Andersen To: Kees Cook Cc: Daniel Borkmann , Alexei Starovoitov , LKML , Network Development , "kernel-hardening@lists.openwall.com" , =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= Subject: Re: [PATCH] ebpf: verify the output of the JIT Message-ID: <20170405034536.oulhc3ylhlrfgqeg@docker> References: <20170404220810.14250-1-tycho@docker.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.6.2-neo (2016-08-21) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1241 Lines: 28 Hi Kees, On Tue, Apr 04, 2017 at 03:17:57PM -0700, Kees Cook wrote: > On Tue, Apr 4, 2017 at 3:08 PM, Tycho Andersen wrote: > > The goal of this patch is to protect the JIT against an attacker with a > > write-in-memory primitive. The JIT allocates a buffer which will eventually > > be marked +x, so we need to make sure that what was written to this buffer > > is what was intended. > > > > We acheive this by building a hash of the instruction buffer as > > instructions are emittted and then comparing that to a hash at the end of > > the JIT compile after the buffer has been marked read-only. > > > > Signed-off-by: Tycho Andersen > > CC: Daniel Borkmann > > CC: Alexei Starovoitov > > CC: Kees Cook > > CC: Micka?l Sala?n > > Cool! This closes the race condition on producing the JIT vs going > read-only. I wonder if it might be possible to make this a more > generic interface to the BPF which would be allocate the hash, provide > the update callback during emit, and then do the hash check itself at > the end of bpf_jit_binary_lock_ro()? Yes, probably so. I can look into that for the next version. Tycho