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 X-Spam-Level: X-Spam-Status: No, score=-7.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86F42C433DF for ; Thu, 30 Jul 2020 08:29:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 63F4220838 for ; Thu, 30 Jul 2020 08:29:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="fBwCfM3r" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729063AbgG3I3M (ORCPT ); Thu, 30 Jul 2020 04:29:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726819AbgG3I3L (ORCPT ); Thu, 30 Jul 2020 04:29:11 -0400 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C340FC061794 for ; Thu, 30 Jul 2020 01:29:10 -0700 (PDT) Received: by mail-ej1-x641.google.com with SMTP id g19so13291904ejc.9 for ; Thu, 30 Jul 2020 01:29:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=YBY55dkNJa6MNA1jcnxEfs+ZojHip66cdlon0CLkLZo=; b=fBwCfM3rpVy2pygAPHKVmWM18+gil7jTPat96H4u/Gm1341wxS3sJ+mdOPhd0Ut2gt RGcV9uVmJNYF/aox3YJfC339GEOZyKzkvnig7ENn+Ejdhc3AjAgNrZhFKAgMljasBEz1 HJDwzRVIamhLhFbHFIM5sP6ok6r4YcePymvRopVYR31uyoVTYDKPtjD/kaUQNEMsbrWe fPrrd+MBFMzEcT8plABi1N+MFxOSMXtsug3boBgJitNyx6gMbxnULwyy8moTml4yYj7h bTR4nD9JeIEUG8hkrNRaXL9u4HeGM1UIvKJCsKhfWnw1LUsAHJTCdFyno5UVFlf+gTKU JtRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=YBY55dkNJa6MNA1jcnxEfs+ZojHip66cdlon0CLkLZo=; b=rHQ1S6H4a+MQwAhPB37rP8slHiLgcSvpD4tiBD+vsfYRPbWHwo54dKUFebD/jxYCgx 13Wn0xxUbOZ8YzZj7ak/7kE3aNf7Ka1Dzm8fKEmZZr6CLhAXc74IBhwO/AcC57kffmk0 Q4oyPlXwH8GFcMmXlSj/taBi7zsUdbkMwDQL3r0DK2JGgOFniQBbEtokRrgybTT7pz8O 8jBZ9ai6P3nWVYt8BfqIGBLq6SW7GQCB8mV6JjIsrk7oJNKrXkX9DEWhpfKQXA3MaFIN kgOX3QFO1nS7F+xd1Erww507Aso37ghM5fZmflVPPVEwcqOKXruwS3OLU4ouNblLgcSV zCPg== X-Gm-Message-State: AOAM5301ONXrTw/YXdEHtofexLq75eP+IJWRJaO8HagOcPq7f44eJku0 HvzgIM+mMtV8BQFUpxdCWEcvjA== X-Google-Smtp-Source: ABdhPJxdK8dE2vli7YDSeq7BM4kuHoJGKCZ1PXuThc9tOBZnCVx4E2ji9ZYap5m6mQi1LmC8Wm6O8g== X-Received: by 2002:a17:907:204e:: with SMTP id pg14mr1606214ejb.324.1596097749512; Thu, 30 Jul 2020 01:29:09 -0700 (PDT) Received: from myrica ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id ay5sm5190070edb.2.2020.07.30.01.29.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jul 2020 01:29:08 -0700 (PDT) Date: Thu, 30 Jul 2020 10:28:53 +0200 From: Jean-Philippe Brucker To: Daniel Borkmann Cc: Song Liu , linux-arm-kernel@lists.infradead.org, bpf , Catalin Marinas , Will Deacon , Alexei Starovoitov , zlim.lnx@gmail.com, Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh Subject: Re: [PATCH bpf-next 1/1] arm64: bpf: Add BPF exception tables Message-ID: <20200730082853.GA1529030@myrica> References: <20200728152122.1292756-1-jean-philippe@linaro.org> <20200728152122.1292756-2-jean-philippe@linaro.org> <4791872a-9f7e-1c1c-392c-8b68a13091e3@iogearbox.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4791872a-9f7e-1c1c-392c-8b68a13091e3@iogearbox.net> Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Wed, Jul 29, 2020 at 11:29:43PM +0200, Daniel Borkmann wrote: > On 7/29/20 7:28 PM, Song Liu wrote: > > On Tue, Jul 28, 2020 at 8:37 AM Jean-Philippe Brucker > > wrote: > > > > > > When a tracing BPF program attempts to read memory without using the > > > bpf_probe_read() helper, the verifier marks the load instruction with > > > the BPF_PROBE_MEM flag. Since the arm64 JIT does not currently recognize > > > this flag it falls back to the interpreter. > > > > > > Add support for BPF_PROBE_MEM, by appending an exception table to the > > > BPF program. If the load instruction causes a data abort, the fixup > > > infrastructure finds the exception table and fixes up the fault, by > > > clearing the destination register and jumping over the faulting > > > instruction. > > > > > > To keep the compact exception table entry format, inspect the pc in > > > fixup_exception(). A more generic solution would add a "handler" field > > > to the table entry, like on x86 and s390. > > > > > > Signed-off-by: Jean-Philippe Brucker > > > > This patch looks good to me. > > > > Acked-by: Song Liu > > +1, applied, thanks a lot! > > > It is possible to add a selftest for this? I thought about this a > > little bit, but > > didn't get a good idea. > > Why not adding a test_verifier.c test case which calls into bpf_get_current_task() > to fetch pointer to current and then read out some field via BPF_PROBE_MEM which > should then succeed on x86/s390x/arm64 but be skipped on the other archs? Jean-Philippe, > could you look into following up with such test case(s)? Sure I'll take a look. Ilya also added a selftests to trigger exceptions in https://lore.kernel.org/bpf/20200715233301.933201-5-iii@linux.ibm.com/ It's useful but I think it relies on the verifier not mandating NULL checks for next-level pointers (they are ptr_ instead of ptr_or_null_), which might change in the future. So I'm wondering if we can deliberately access an invalid pointer with the help of bpf_test_run, and check that the result is zero. Thanks, Jean 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 X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1355AC433E0 for ; Thu, 30 Jul 2020 08:30:52 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D312820838 for ; Thu, 30 Jul 2020 08:30:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Z4gHMfWJ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="fBwCfM3r" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D312820838 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=4Gznaxzq/orblTqNpU7sLh3ZZe9iD2uknRP7q8Myfhw=; b=Z4gHMfWJ4rgFpH3fDo80e563H 0F/z5aCGPJ7brQ6yTA1RlLoiJWQWc0FumLUF36KSdT0UqqMYO4/bFxZr/7AYdQ4bDC/kgZPP+Yivb WZOIX7i4bJIP1+lJHEWYhzOyD8OpM1WN4sk9HPxGKiB+oOVCultS+LvJ5DQH3k8CFeye5HOTHRSWY dcttJgZ4Tnaf668PluI7zVL1yCMcBGJIgBYQ5uMfHBQX8xTAVJlyuAqiXv20hEllwnpeIb2ONBpUm Z+jyzun2f3vG4CALT9sZZ7mYCR8+HmAXHRPxX7XV9Ss4qNNJwXd+rXRmPM3VOQ5WjjcKFnRKBBUDq XhT+pscXw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k13wA-0006m0-KC; Thu, 30 Jul 2020 08:29:14 +0000 Received: from mail-ej1-x644.google.com ([2a00:1450:4864:20::644]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k13w8-0006lN-7o for linux-arm-kernel@lists.infradead.org; Thu, 30 Jul 2020 08:29:13 +0000 Received: by mail-ej1-x644.google.com with SMTP id d6so13268779ejr.5 for ; Thu, 30 Jul 2020 01:29:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=YBY55dkNJa6MNA1jcnxEfs+ZojHip66cdlon0CLkLZo=; b=fBwCfM3rpVy2pygAPHKVmWM18+gil7jTPat96H4u/Gm1341wxS3sJ+mdOPhd0Ut2gt RGcV9uVmJNYF/aox3YJfC339GEOZyKzkvnig7ENn+Ejdhc3AjAgNrZhFKAgMljasBEz1 HJDwzRVIamhLhFbHFIM5sP6ok6r4YcePymvRopVYR31uyoVTYDKPtjD/kaUQNEMsbrWe fPrrd+MBFMzEcT8plABi1N+MFxOSMXtsug3boBgJitNyx6gMbxnULwyy8moTml4yYj7h bTR4nD9JeIEUG8hkrNRaXL9u4HeGM1UIvKJCsKhfWnw1LUsAHJTCdFyno5UVFlf+gTKU JtRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=YBY55dkNJa6MNA1jcnxEfs+ZojHip66cdlon0CLkLZo=; b=crdiNXPeQnRQrlq7eZI+mWllvVw2bLQwwVYBvcHkbEFAEVk7/8M6C4CtSwvmeilKar vG/3ASMUMejHFJfodqmPFGyibVd6tva+nqAigrg7qmTmrDslU582Cc31hX2W8zIHTsSu dWZrLVIDuYq2AwbeGbBXvQQG777eerUqmaq/4802MLwIeGR3Ao7urMAWQsJkENH9xiVl tpZ1UuBrRylPGmtjcYj3xvNg8vQVzYZISVslwA9kjiRcpXnqfDWQzph/o3aA7+qIY52u 1qbW1PcMcETiK/Xc24WFEjMcZSv9qPRBPQPgmIxSO0gxdaF5HwyT/B9CVXmxpqet/vRZ xL5Q== X-Gm-Message-State: AOAM533DJBQkvPMRBENoDAisOjbQbTc2D4OFRqsk1rYlGQx0ziaowm+F 36Y317uenESLbLl+NfvhxidBEw== X-Google-Smtp-Source: ABdhPJxdK8dE2vli7YDSeq7BM4kuHoJGKCZ1PXuThc9tOBZnCVx4E2ji9ZYap5m6mQi1LmC8Wm6O8g== X-Received: by 2002:a17:907:204e:: with SMTP id pg14mr1606214ejb.324.1596097749512; Thu, 30 Jul 2020 01:29:09 -0700 (PDT) Received: from myrica ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id ay5sm5190070edb.2.2020.07.30.01.29.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jul 2020 01:29:08 -0700 (PDT) Date: Thu, 30 Jul 2020 10:28:53 +0200 From: Jean-Philippe Brucker To: Daniel Borkmann Subject: Re: [PATCH bpf-next 1/1] arm64: bpf: Add BPF exception tables Message-ID: <20200730082853.GA1529030@myrica> References: <20200728152122.1292756-1-jean-philippe@linaro.org> <20200728152122.1292756-2-jean-philippe@linaro.org> <4791872a-9f7e-1c1c-392c-8b68a13091e3@iogearbox.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4791872a-9f7e-1c1c-392c-8b68a13091e3@iogearbox.net> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200730_042912_336450_A18F0F7A X-CRM114-Status: GOOD ( 25.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Song Liu , Andrii Nakryiko , Catalin Marinas , John Fastabend , Alexei Starovoitov , Song Liu , zlim.lnx@gmail.com, KP Singh , Yonghong Song , bpf , Will Deacon , Martin KaFai Lau , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Jul 29, 2020 at 11:29:43PM +0200, Daniel Borkmann wrote: > On 7/29/20 7:28 PM, Song Liu wrote: > > On Tue, Jul 28, 2020 at 8:37 AM Jean-Philippe Brucker > > wrote: > > > > > > When a tracing BPF program attempts to read memory without using the > > > bpf_probe_read() helper, the verifier marks the load instruction with > > > the BPF_PROBE_MEM flag. Since the arm64 JIT does not currently recognize > > > this flag it falls back to the interpreter. > > > > > > Add support for BPF_PROBE_MEM, by appending an exception table to the > > > BPF program. If the load instruction causes a data abort, the fixup > > > infrastructure finds the exception table and fixes up the fault, by > > > clearing the destination register and jumping over the faulting > > > instruction. > > > > > > To keep the compact exception table entry format, inspect the pc in > > > fixup_exception(). A more generic solution would add a "handler" field > > > to the table entry, like on x86 and s390. > > > > > > Signed-off-by: Jean-Philippe Brucker > > > > This patch looks good to me. > > > > Acked-by: Song Liu > > +1, applied, thanks a lot! > > > It is possible to add a selftest for this? I thought about this a > > little bit, but > > didn't get a good idea. > > Why not adding a test_verifier.c test case which calls into bpf_get_current_task() > to fetch pointer to current and then read out some field via BPF_PROBE_MEM which > should then succeed on x86/s390x/arm64 but be skipped on the other archs? Jean-Philippe, > could you look into following up with such test case(s)? Sure I'll take a look. Ilya also added a selftests to trigger exceptions in https://lore.kernel.org/bpf/20200715233301.933201-5-iii@linux.ibm.com/ It's useful but I think it relies on the verifier not mandating NULL checks for next-level pointers (they are ptr_ instead of ptr_or_null_), which might change in the future. So I'm wondering if we can deliberately access an invalid pointer with the help of bpf_test_run, and check that the result is zero. Thanks, Jean _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel