Received: by 10.213.65.68 with SMTP id h4csp654546imn; Tue, 13 Mar 2018 16:46:46 -0700 (PDT) X-Google-Smtp-Source: AG47ELsZ3ftjS++uIxJsSTFwTMzGmEgJBd9juENQjEYAjfbigYkFdtyHTSksvekmMWIrgMTih145 X-Received: by 10.99.105.70 with SMTP id e67mr1930645pgc.342.1520984806284; Tue, 13 Mar 2018 16:46:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520984806; cv=none; d=google.com; s=arc-20160816; b=Vg9JrQHVFkrJba7SYXyAw3KB7TEw/S3kADbC64xCJ4RHY9MhHYtuCigaNoqN9WCAdA YXROrobPy7YrjWa1JB9E/MIuKtquN/Qahp+ZilKfm9uNQcIGob48irgtmlfchr6Orpb9 eGFpb5BbqCeUbNpFzXBTHOhESq8uxvrBDUBZ7iI/rV3puVWVuGYe5+8ZHpWkEOcGNvFi upLHKiOvhC8SpG3nU2bwz4Ci1tLHLlCfjf1clTK58Nr9Rn6E2oqH8ak2jzNPXs70a3/l iieLEmDfyO9IRfPY8V08Jj+QQg9XLDRbqWjQ5ulVwpHznpLotPGrizg7CDQdqAu9EoLQ OHbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=JM7Xsihh5bpIAXAyi4MsduwX01q5VXoz3RG+EQCfO/8=; b=BcWJ0/zGmUMirQK/e4Q3xUUrErj6xORY/DOk8aNF0JyXOUuNy11fuyGWSdTW59DChs TTtd6HCWTnws2pvYlK9kG3Bt5I4G1DUe94rGcHksozYcU3sjmO4hntVb4NTdw0LybjRr B10vXQwfwK1nKgtCzyEeYbjdWHcVPzMLc3v6iG+GibfuA+pP4cn39+fxiTzGgool7342 ig2gAzr1iD02w6ygSjPyN+aan1+KMKcrOraPRgPbXJ+2cXWgiHwPRMKUKQbVK4UQ2pCi DzFH2utnS6zUuE796qE3KNqFM724yK2S/f7UuW/APHwRWvMXyK4ubbhJIuuPHnrV8RZE BPIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@osandov-com.20150623.gappssmtp.com header.s=20150623 header.b=E3lTkc3N; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m12-v6si910240pll.549.2018.03.13.16.46.30; Tue, 13 Mar 2018 16:46:46 -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=@osandov-com.20150623.gappssmtp.com header.s=20150623 header.b=E3lTkc3N; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932789AbeCMXpO (ORCPT + 99 others); Tue, 13 Mar 2018 19:45:14 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:36740 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753113AbeCMXpL (ORCPT ); Tue, 13 Mar 2018 19:45:11 -0400 Received: by mail-pf0-f195.google.com with SMTP id 68so606517pfx.3 for ; Tue, 13 Mar 2018 16:45:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=JM7Xsihh5bpIAXAyi4MsduwX01q5VXoz3RG+EQCfO/8=; b=E3lTkc3NeHJSeKPAu5GbrzFY/ZmTYBcc43of5FGUrqrkDEEXxNVS9DCcPgHbbEmVIH wHr9TL6JNiBFESy5JcGiaMhyaChG6bDIm/8hm75jI/Bmwf+1UDLK7zeyldNY7QN1wwCt cZPqCdWxnuefa0u551ywXQlCTqgJTtLu8NEoNoaeCyCmPBrcbnZDAkttuVZMfqyg+gib iQrS52YV6Xz7sc/uNQTDFfA6nlirc3I4B7g9jVYbiWvjQDRpZL7wZBYxHs9U/Sb/ySIQ OB3qVnsdMLAr7Ibd9TUplo723VzivREgQXMeS2hyfZqTuTEUIYARv1E4EqXNKb2ieOLL LEAA== 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:user-agent; bh=JM7Xsihh5bpIAXAyi4MsduwX01q5VXoz3RG+EQCfO/8=; b=OhmjQPPQbInR35kiUFKxVTzH+64Mz9KqOUeKXXOmW7e3ftKgtpd7Fx65C55htWkuVw EOh4KljSOrXghVxK4oR5MzX5Ui9rIo0tzfToAmlCcA4TUh9JkfIYYgnOq0yyclngQyad a0VytAuWXQ/HQD2GUAku9tH1E1+651IfgmOR0U5vTb0DxTOnGHZOAKTULRhV1Jc+Y3+E kooZPLcBY/mbiTOyuo+9DwcjDaPTVYQADbgeS0/SdMU/QoJu/OI8+dYIwWNrqmguDfz/ 15bHn+8eRCXHdCBrLvZfzihR54oiKOqh1I6YRPj2Wwlso5w711h+Bhl5cQaZnungN3AN 1Uqg== X-Gm-Message-State: AElRT7H75IFU8iwW+3f1lixGjVH7vKGtU50oXzOuZVwgalBShgidcHmw HUy8FfbwF8VH4mJUkMhYRUcraA== X-Received: by 10.101.87.138 with SMTP id b10mr1907456pgr.241.1520984710677; Tue, 13 Mar 2018 16:45:10 -0700 (PDT) Received: from vader ([2620:10d:c090:200::6:8b45]) by smtp.gmail.com with ESMTPSA id n13sm2311414pfg.45.2018.03.13.16.45.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Mar 2018 16:45:10 -0700 (PDT) Date: Tue, 13 Mar 2018 16:45:09 -0700 From: Omar Sandoval To: Howard McLauchlan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Al Viro , Thomas Gleixner , Yonghong Song , "David S . Miller" , Thomas Garnier , kernel-team@fb.com, Steven Rostedt , Ingo Molnar , Josef Bacik , Alexei Starovoitov , netdev@vger.kernel.org Subject: Re: [PATCH] bpf: whitelist syscalls for error injection Message-ID: <20180313234509.GA4981@vader> References: <20180313231627.1247-1-hmclauchlan@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180313231627.1247-1-hmclauchlan@fb.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 13, 2018 at 04:16:27PM -0700, Howard McLauchlan wrote: > 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 > Adding a few more people to Cc