Received: by 10.213.65.68 with SMTP id h4csp646150imn; Tue, 13 Mar 2018 16:21:51 -0700 (PDT) X-Google-Smtp-Source: AG47ELsV5Zlb7609eKRnOOn9lkUuM0w0MueTt/ai8rL4sDkxNlfRqVinryp9k7WlewF0ZcUdPC9P X-Received: by 10.101.91.3 with SMTP id y3mr1900189pgq.149.1520983311467; Tue, 13 Mar 2018 16:21:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520983311; cv=none; d=google.com; s=arc-20160816; b=rkxuxpzi7KxuWaERz8+Mt+HKyLpIeDJrwR+XlKtTQ3lR23QoOHzAG9IxqqSXN44r5c e0wybWhhmlhXX089zk2cSt3yHWhf9SzpGx+ZyRCj17AsOdwN0vwi3anKLhUgqtmse7h/ qT+FjBU0GMuJURE9rrKHVgG6Wq/8F89lehp8a2N4jB1kV/9uL9s7AcEtNJyh+bfHqHEg xE/HyKKmgLElSkSilyXQt7v0RYifuG9RflFf5TXodq1d8dzcy72pD3DwmkcRPdqV7M4O LayvoZuSCGvjztiSCkOkThcPcsaMMhtK+vG8hS/Kv1yScdCcMvmcdHa3LE6YCjipi+EF AHZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:message-id:date:subject:cc:to :from:dkim-signature:dkim-signature:arc-authentication-results; bh=xb82nA8B5KPNCprP8jrKmHzqvCH29UEt6ANK0npthFI=; b=iDYZG73BG9FskjgN3fCiE6toXBOLEWwGqSdR4IeKNnMDyb+RnZ87+TLxFtFYhalg1V bALC2nuQ9rITjoqKxzact5CbELbPjE05GLb238wBjV/Vh/JelauJ2PdZSU3asfod/xiF 2A4bG0Yw1pp9DsmPdHrUd/DP+8H//e2SLsFipKOiGEYZYGhTLQ0uqpeME9kIIo8sxyES qMRC5bcpgQQ6urLwlfObvyBsm7filzmJ4d+zCFoyuoRj0KRH5wSQ1D/L8gGqPLUSjx0q 34SWiBfDq/16Sva99j38KbFrk+wRHp820NOydzk+sUu0loIdjQbOdh5jNtemCblcbfVG WmsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=Z5K6H3ns; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=VPzk3mVf; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 68-v6si883355pla.343.2018.03.13.16.21.37; Tue, 13 Mar 2018 16:21:51 -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=pass header.i=@fb.com header.s=facebook header.b=Z5K6H3ns; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=VPzk3mVf; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932763AbeCMXUd (ORCPT + 99 others); Tue, 13 Mar 2018 19:20:33 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:43862 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932240AbeCMXUa (ORCPT ); Tue, 13 Mar 2018 19:20:30 -0400 Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2DNK3iC016464; Tue, 13 Mar 2018 16:20:21 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=facebook; bh=xb82nA8B5KPNCprP8jrKmHzqvCH29UEt6ANK0npthFI=; b=Z5K6H3nsKYPYExx65pDo/90rklgFXt7iSBR5ySR2anIIqOGWwbJ3eTFarbQ+XZnOXWiq qH0CpbyYcib+2mN1ymGd6Bg0MRIkaj5HLkQIeNoT6tSqpk94/1/ZOfOijOGHWSkFzhUP fLBvqKmjxg9omgzfQh05Kyp2P8gpcZHYdKs= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2gpqq9r3bp-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 13 Mar 2018 16:20:21 -0700 Received: from NAM03-BY2-obe.outbound.protection.outlook.com (192.168.54.28) by o365-in.thefacebook.com (192.168.16.20) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 13 Mar 2018 16:20:20 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=xb82nA8B5KPNCprP8jrKmHzqvCH29UEt6ANK0npthFI=; b=VPzk3mVfRMkN76FtSVbqZ6HGWGkCMHBZjjpZgY6HUBPQafD5H89MMiY6HVme6Fd4ivp41G2NBx8rKn8ZvoDdbRHBPOFvxDu6Lx7bE+IhTgU6ymLnqSeRQGsQPFvqIsi+pQD5IGDf1J/pevSOMbLxBu/V9hv7LyJd+xdSeJ6TABY= Received: from hmclauchlan-ubu470.thefacebook.com (2620:10d:c090:200::5:747) by DM3PR15MB0539.namprd15.prod.outlook.com (2a01:111:e400:c477::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.548.13; Tue, 13 Mar 2018 23:20:00 +0000 From: Howard McLauchlan To: CC: , Al Viro , Thomas Gleixner , Yonghong Song , "David S . Miller" , Thomas Garnier , , Howard McLauchlan Subject: [PATCH] bpf: whitelist syscalls for error injection Date: Tue, 13 Mar 2018 16:16:27 -0700 Message-ID: <20180313231627.1247-1-hmclauchlan@fb.com> X-Mailer: git-send-email 2.14.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [2620:10d:c090:200::5:747] X-ClientProxiedBy: MWHPR10CA0051.namprd10.prod.outlook.com (2603:10b6:300:2c::13) To DM3PR15MB0539.namprd15.prod.outlook.com (2a01:111:e400:c477::25) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e02040bf-218e-4fef-2edf-08d58938f1cb X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020);SRVR:DM3PR15MB0539; X-Microsoft-Exchange-Diagnostics: 1;DM3PR15MB0539;3:HNmFNIsqrNb0OK2EBqe85+dmlwuZdRzxKK+Of9ICZmh7mjeFCB9Ujk8rorwmKgvHFqdm7H7quRIGIMQCVKDo1Xb59MEwJdX5DItvXsSWzI69P65kOsU7nPqyHgCseXIA6uTW0BZp72emtjL8KUvJLzktEgD5ui9l6UtOQFXnSOU1o+05AGo6anair+jYkzfWvz/VTn0oJ4aOAqzJK2b8re2RipDkI3o36ZVTivMAYE6oSkoNpvTgvlLVTCF//Juw;25:5guWVcCxCvMdGZFHW7kypm88E9TVclUQ935yG6PyPdauxMGfnDUYBq2Uj/Ibe8vhpNL7JYbPDAUmGihi30zbq8wuTs0zjA4KTGQy0FLicIF2DRRhAPSTmBdF8OTjbTYlvfwDv2h6VD3sdo8b9A1BVhteqb7z9i+uxn2Eu6k6eWzd8i3GMo4WcnIpOtoZkIN553i+dwRew0WWxjR9LntaHB2IQejDGlG5XOcSwqFqv42rx7dJr2UyqZ8JgZ9LSYNtatxmQloqEeT1JHf6foY1LsQAl8/gX3dQ7B9whFRhI2uK64i0z76XYUShNf75UDV3jX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C/xIB8McPiPnWEsF+wOXRZEewvJFSqDav23iibRqM1nNb0KhRyQ1mc4lWvBoL80OJPHvlBmZz413gfvzUQojdu822b7Qk5uDnypJzKXv X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(3002001)(93006095)(93001095)(3231221)(11241501184)(944501244)(52105095)(6041310)(20161123562045)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(6072148)(201708071742011);SRVR:DM3PR15MB0539;BCL:0;PCL:0;RULEID:;SRVR:DM3PR15MB0539; X-Forefront-PRVS: 0610D16BBE X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(376002)(366004)(346002)(396003)(39380400002)(39860400002)(189003)(199004)(48376002)(8936002)(2361001)(16586007)(81166006)(1857600001)(53936002)(4326008)(86362001)(50226002)(5660300001)(36756003)(47776003)(81156014)(7736002)(305945005)(25786009)(8676002)(6506007)(52396003)(69596002)(50466002)(52116002)(51416003)(6116002)(386003)(16526019)(106356001)(6666003)(6486002)(1076002)(97736004)(53416004)(2906002)(316002)(105586002)(6916009)(186003)(6512007)(68736007)(478600001)(2351001)(46003)(54906003);DIR:OUT;SFP:1102;SCL:1;SRVR:DM3PR15MB0539;H:hmclauchlan-ubu470.thefacebook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; Received-SPF: None (protection.outlook.com: fb.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DM3PR15MB0539;23:5fuH3kAU4OuD8UihsNhVE7uV6xw+zxsQlP59oxAzj?= =?us-ascii?Q?2m7SV3L46Ic7oeWVyng2eeQWYhHacMWtsYVx2WE5sfBW77TEppHAjm8FMWaI?= =?us-ascii?Q?RHDNbYJEEvMbPOl10DOa4cJZyJFwLG1W0sxQM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i9i2iSjbtVd6sElJDy1amKp/suTXe+PHD3wI4aTpChCKhv2YIJch93jgk=;7:A8sFmxsWEvhGjilQpguzLORA/d5QOa4Y02lQ49ONc5qwuKJ/D5WepCHKSgye6RGBBAwkx6DkPhHPMiNIfLwpRx184AFDASUz5B9PwvsNsPugzbVIccAKxFndWaDcEgC0YhdSYcVR1qjl3AYzsNbq1d10LVrtHCmd9rsVAOJHdJWIWTl6z3X64mpDQZhxHLNjpbzL8iocQ+b6f8lZkMVqVE1CYrQEvpD0WAr4MahMq3YesaU2PxySB8JTlf1DbW47 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DM3PR15MB0539;20:H9FIRv6jYY2isqx81rcVuyjlzESPnr8NJuPDJS1ucPg16uKJKrjtc9NilqFSBoTfFJuMvLV5yujFuVUJhUl5F5yW4HQCyrPChPmGbx1kN3JrhJR4+hnLLhEgOb2uwjqyh2rIRI82tYShNm2u1iTOWZg8OGFOqNDJ4tO2XZAfMWc= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2018 23:20:00.4185 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e02040bf-218e-4fef-2edf-08d58938f1cb X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR15MB0539 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-03-13_10:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Error injection is a useful mechanism to fail arbitrary kernel functions. However, it is often hard to guarantee an error propagates appropriately to user space programs. By injecting into syscalls, we can return arbitrary values to user space directly; this increases flexibility and robustness in testing, allowing us to test user space error paths effectively. The following script, for example, fails calls to sys_open() from a given pid: from bcc import BPF from sys import argv pid = argv[1] prog = r""" int kprobe__SyS_open(struct pt_regs *ctx, const char *pathname, int flags) { u32 pid = bpf_get_current_pid_tgid(); if (pid == %s) bpf_override_return(ctx, -ENOENT); return 0; } """ % pid b = BPF(text = prog) while 1: b.perf_buffer_poll() This patch whitelists all syscalls defined with SYSCALL_DEFINE for error injection. Signed-off-by: Howard McLauchlan --- based on 4.16-rc5 include/linux/syscalls.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index a78186d826d7..e8c6d63ace78 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -191,6 +191,8 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event) #define SYSCALL_DEFINE0(sname) \ SYSCALL_METADATA(_##sname, 0); \ + asmlinkage long sys_##sname(void); \ + ALLOW_ERROR_INJECTION(sys_##sname, ERRNO); \ asmlinkage long sys_##sname(void) #define SYSCALL_DEFINE1(name, ...) SYSCALL_DEFINEx(1, _##name, __VA_ARGS__) @@ -210,6 +212,7 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event) #define __SYSCALL_DEFINEx(x, name, ...) \ asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \ __attribute__((alias(__stringify(SyS##name)))); \ + ALLOW_ERROR_INJECTION(sys##name, ERRNO); \ static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \ asmlinkage long SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \ asmlinkage long SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \ -- 2.14.1