From patchwork Thu Apr 26 09:57:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang YanQing X-Patchwork-Id: 904958 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="fI6PXdCh"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40WsvQ1373z9rxs for ; Thu, 26 Apr 2018 19:58:10 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755205AbeDZJ57 (ORCPT ); Thu, 26 Apr 2018 05:57:59 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:39819 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753879AbeDZJ5t (ORCPT ); Thu, 26 Apr 2018 05:57:49 -0400 Received: by mail-pf0-f195.google.com with SMTP id z9so17907562pfe.6; Thu, 26 Apr 2018 02:57:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mail-followup-to:mime-version :content-disposition:user-agent; bh=aupfcqkG003Oemh5u18X7AzJIHI3t/E6A9ywFgfMI6Y=; b=fI6PXdChPZeK3Y+2k3GFllBgJyx0gzEhs+Deg8kTWTsM0gwSrn3cjDm7ow259aiBck RZt0hxhkD+4eOb0F9x8mq52N4zCs+E35NXwpmkToL6rVzwXW56UiQs2U8sPstH2OYIEM eSFJ/BKkU0TS8zTGNqwcGA+QR+Q0JZAvFC6OxOtKnkrGPMaqGFhF2lWzkaFKZ96VhSQ1 YC6nEY4+GOGgwgzbkCcdx/h0Bthgt1B5ufQKSCnu8G8eviuD5zsKQw4qC9tCl/cG/Rj6 p2Q3G6hzwiHwwq7WbPEHkGv7HGrgFvAKghIxtzmZvWVbO9penniQzpVnzjJsHnWxg3cS nAjQ== 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 :mail-followup-to:mime-version:content-disposition:user-agent; bh=aupfcqkG003Oemh5u18X7AzJIHI3t/E6A9ywFgfMI6Y=; b=JqVQLOOpKm96GRAxq4x806BWv9QYRn1X2zYzYY4rbgBTy0d/PWW3Db0TtgFFVzSfey rZuRmWjeWATEHei9s4WjhEVJZgKx31MH/QlVYdO3YcEYXv8bQCmz5/aOzKm3fhU9LKVY i+NvkW8KXut+nOKBKInbm8G2GyAHUb2uoMFQoJfU4w8/L/RSyzXzWpT8i5BpntYrsXCN wmbrWSlCMMa91GImYXFWN1kvrVsHdJLwfuNnVwdGA5Yt7+1YUChwFZomIv9QU0W620ai dz5Lln0v3XbUuctZRHH6JjVyeI83RCMGZPJ9LnItlHj6dK4D1UO9sNqRxYpta9xirVgg 4cQA== X-Gm-Message-State: ALQs6tDJF1wRXuZ2cKXpgUSLcrNOMBkWcPyOFO5Ob0Zyn/Cf+1M+N3IG 48HdSPSDpbFYya7Gv2Q2nqj5vf7H X-Google-Smtp-Source: AB8JxZq0/V0AG2ezs/50yHqigX8PiXJMB1HP+TsNhxk8j9R4qbs7TgHJs+Qm81ru3fBnGkMlyQGu8w== X-Received: by 2002:a17:902:758a:: with SMTP id j10-v6mr4402060pll.11.1524736668706; Thu, 26 Apr 2018 02:57:48 -0700 (PDT) Received: from udknight.localhost ([183.90.36.235]) by smtp.gmail.com with ESMTPSA id y13sm35325814pge.34.2018.04.26.02.57.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Apr 2018 02:57:48 -0700 (PDT) Received: from udknight.localhost (localhost [127.0.0.1]) by udknight.localhost (8.14.9/8.14.9) with ESMTP id w3Q9voD0029331; Thu, 26 Apr 2018 17:57:50 +0800 Received: (from root@localhost) by udknight.localhost (8.14.9/8.14.9/Submit) id w3Q9vncP029330; Thu, 26 Apr 2018 17:57:49 +0800 Date: Thu, 26 Apr 2018 17:57:49 +0800 From: Wang YanQing To: daniel@iogearbox.net Cc: ast@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] bpf: fix misaligned access for BPF_PROG_TYPE_PERF_EVENT program type on x86_32 platform Message-ID: <20180426095749.GA29207@udknight> Mail-Followup-To: Wang YanQing , daniel@iogearbox.net, ast@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org All the testcases for BPF_PROG_TYPE_PERF_EVENT program type in test_verifier(kselftest) report below errors on x86_32: " 172/p unpriv: spill/fill of different pointers ldx FAIL Unexpected error message! 0: (bf) r6 = r10 1: (07) r6 += -8 2: (15) if r1 == 0x0 goto pc+3 R1=ctx(id=0,off=0,imm=0) R6=fp-8,call_-1 R10=fp0,call_-1 3: (bf) r2 = r10 4: (07) r2 += -76 5: (7b) *(u64 *)(r6 +0) = r2 6: (55) if r1 != 0x0 goto pc+1 R1=ctx(id=0,off=0,imm=0) R2=fp-76,call_-1 R6=fp-8,call_-1 R10=fp0,call_-1 fp-8=fp 7: (7b) *(u64 *)(r6 +0) = r1 8: (79) r1 = *(u64 *)(r6 +0) 9: (79) r1 = *(u64 *)(r1 +68) invalid bpf_context access off=68 size=8 378/p check bpf_perf_event_data->sample_period byte load permitted FAIL Failed to load prog 'Permission denied'! 0: (b7) r0 = 0 1: (71) r0 = *(u8 *)(r1 +68) invalid bpf_context access off=68 size=1 379/p check bpf_perf_event_data->sample_period half load permitted FAIL Failed to load prog 'Permission denied'! 0: (b7) r0 = 0 1: (69) r0 = *(u16 *)(r1 +68) invalid bpf_context access off=68 size=2 380/p check bpf_perf_event_data->sample_period word load permitted FAIL Failed to load prog 'Permission denied'! 0: (b7) r0 = 0 1: (61) r0 = *(u32 *)(r1 +68) invalid bpf_context access off=68 size=4 381/p check bpf_perf_event_data->sample_period dword load permitted FAIL Failed to load prog 'Permission denied'! 0: (b7) r0 = 0 1: (79) r0 = *(u64 *)(r1 +68) invalid bpf_context access off=68 size=8 " This patch fix it, the fix isn't only necessary for x86_32, it will fix the same problem for other platforms too, if their size of bpf_user_pt_regs_t can't divide exactly into 8. Signed-off-by: Wang YanQing --- Hi all! After mainline accept this patch, then we need to submit a sync patch to update the tools/include/uapi/linux/bpf_perf_event.h. Thanks. include/uapi/linux/bpf_perf_event.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/uapi/linux/bpf_perf_event.h b/include/uapi/linux/bpf_perf_event.h index eb1b9d2..ff4c092 100644 --- a/include/uapi/linux/bpf_perf_event.h +++ b/include/uapi/linux/bpf_perf_event.h @@ -12,7 +12,7 @@ struct bpf_perf_event_data { bpf_user_pt_regs_t regs; - __u64 sample_period; + __u64 sample_period __attribute__((aligned(8))); __u64 addr; };