Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755922AbdLTRdw (ORCPT ); Wed, 20 Dec 2017 12:33:52 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:45914 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755758AbdLTRdt (ORCPT ); Wed, 20 Dec 2017 12:33:49 -0500 Subject: Re: [PATCH v10 1/5] add infrastructure for tagging functions as error injectable To: Masami Hiramatsu , Josef Bacik References: <1513365176-6744-1-git-send-email-josef@toxicpanda.com> <1513365176-6744-2-git-send-email-josef@toxicpanda.com> <20171220200051.3d2adbde962e20f356b18338@kernel.org> CC: , , , , , , , , , , Josef Bacik From: Alexei Starovoitov Message-ID: <285ac928-a7b0-b0a1-79cb-6fa5d4b24e52@fb.com> Date: Wed, 20 Dec 2017 09:33:13 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <20171220200051.3d2adbde962e20f356b18338@kernel.org> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [2620:10d:c090:180::c592] X-ClientProxiedBy: SN4PR0501CA0057.namprd05.prod.outlook.com (2603:10b6:803:41::34) To BL2PR15MB0963.namprd15.prod.outlook.com (2603:10b6:201:15::25) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8114ffe7-47ba-4658-69ad-08d547cfc2f1 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(5600026)(4604075)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(2017052603307)(7153060);SRVR:BL2PR15MB0963; X-Microsoft-Exchange-Diagnostics: 1;BL2PR15MB0963;3:b6zYJMBdL6wlUOotpVbkpGJY++QM/LxbJl2GBJtPuDuVl/okPLfAaLeK2QgyR8hmr2toUOaY8L9jbx+lMSJlKGbrb/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aTbV07LkRgZioNk1ei3lEvNCukG4XkeqAHcCAZXScMQNdLVj8DHOYuoR9ltVgpv3oe/Y3y6ZenCxOo++sq4w3kaz0hYjp1xdBhDZT/WCtoIKuzXwV1xO3nHRm2HhWSE3jz+Zr24/VcJNHTgD+5M3y9u0juMLiB1a3zftxUrdm/Z9jabW6xfHjINt6ATQU4b8kJNuUHru0dBj+li21iAoFtW8Pzxh8Xhxakn8CMpeQdlX7blY9k3IstbhR4TB4;4:u2tD/jGl2yKfyP2YryKFFyHg1P0eJKnKLcLa6jS1f1aihilbrISpwnCMWIU/ynslgNHLWO6aerLy4/Gaq9Lta7QjSq3roHrqQUdEIorbIa9urYFptNApnBt2SwLy95KtF8HhGvovmogf+hXbPYf2NFlGpwSIQhvmbGY73jT8o6xgDsXb43mab6Ky16dTIEd1xXkkeGUKDysTa3nLBc17MZ97n4prZpb51ER66xvffaIZHXRbsCT4VgV9FQmrokws7efeOxS8FnhKgwhjV1LdOR/coTXXVBAeicZ5J9YwQs9jBvBicGP9A2bHsfDl2NXq X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(5005006)(8121501046)(3231023)(11241501184)(93006095)(93001095)(10201501046)(3002001)(6041268)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:BL2PR15MB0963;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:BL2PR15MB0963; X-Forefront-PRVS: 0527DFA348 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(39860400002)(366004)(396003)(346002)(376002)(39380400002)(24454002)(189003)(199004)(105586002)(58126008)(50466002)(65826007)(31686004)(386003)(230700001)(53546011)(6116002)(7416002)(110136005)(316002)(1706002)(47776003)(478600001)(68736007)(36756003)(4326008)(59450400001)(65806001)(25786009)(65956001)(5660300001)(53936002)(76176011)(81166006)(8676002)(2906002)(6246003)(81156014)(52116002)(229853002)(106356001)(52396003)(7736002)(2950100002)(31696002)(6666003)(97736004)(305945005)(67846002)(6486002)(86362001)(8936002)(23746002)(64126003)(83506002)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:BL2PR15MB0963;H:[IPv6:2620:10d:c081:1131::1437];FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;BL2PR15MB0963;23:4K6kEBSJtk0kNFG0RMq7HMrG6M1Rln24pkXzV?= =?Windows-1252?Q?Aez4SlDc/5evl8ZWH7FMsEnV3rKLUFNqg4x4tFZIqnyBK5f+kh5RAYsX?= =?Windows-1252?Q?ndPxmyXy4Iy8WhiO8Ok1IdOBO6TiIkjmMLOU2SwWdszlEagrM+NLliMg?= =?Windows-1252?Q?K5tqb6rRI5RGnKGeWKLHvlkbxwDO409uXYi2QuU+nDd0i54g4jovmngD?= =?Windows-1252?Q?uxSzMTln9+RqKABiv+kOz6KCjMuxKEN/JvcqKoJ8rXlA+6WJQzykNINE?= =?Windows-1252?Q?zb/srGIcml2Y2X4P94HqgA/q/VIOcECg4qyA882in6ER2O3vy5HCN8Uz?= =?Windows-1252?Q?l/ERyinyeb1yGRzzO0q4IqDDG1Hzh4Noplkea5QZZZD8mWCF+vezguSz?= =?Windows-1252?Q?BWIzxc05B+tfb/v4fGz8MnL5nRqL/svnesAMIYzCfPW2NB32zgDIZu38?= =?Windows-1252?Q?Y/fMfygaW8qfQmMydvacMX0StfyfHepFKDLTwoDGUSXTofFQ7uQop8iJ?= =?Windows-1252?Q?WzS8myjYexpSRc2pAwgcvh39RQjA2SH3r6OGXxgXJZSflvTMTwJrRlKD?= =?Windows-1252?Q?47EK0ta9ItpRfuYoi3quAi+Wu1RU4L5Jj3qHrGNF+g/Rvm4rw3yo9bM5?= =?Windows-1252?Q?JW6wzJ79wE/mg+vjjDhIEQFHpLcP6TbwkDeXIeiop/K6FQ68w57MaQsV?= =?Windows-1252?Q?VfLnNLYdsfCdlijavtgAhKFV1cgZUd5t/NQn3EulSzDmygiI3OavlCT0?= =?Windows-1252?Q?CLP7H8NqpK6tRHkrY9fN/eJkXszqPeZoQVe/Av0ClfFRQaXwQvJOq0ty?= =?Windows-1252?Q?6DiFQUwtC80JZUyYC3nfRTbCNVq5qVJikAY3nfJnPFbr72dpsUaGBZok?= =?Windows-1252?Q?uh82c10DevuvpUId8LZWHYWsAhwFDY6klhtFcSqS+DHa8jAp33/n6lcc?= =?Windows-1252?Q?Khq2P/Dr+8lbpH6VTuwLtTWn2g7stWxeWIcCppWps/JT8iaahuEEf3QF?= =?Windows-1252?Q?Ffmn4jlvePauNYYF659zCTEf0oW3gDg8B7AeVnfqNUFJugw9SYK4w8yV?= =?Windows-1252?Q?3/tPMwWWfqu90b0UaEA20qgqP5h+XDKZWfxVQbWI6Z3DZTNAOA6qwLLX?= =?Windows-1252?Q?TiUe/dnygaUs9laQxrUehVD4PsESaBXjxaOGof2dNRDL+Fqx/Yh/v1/I?= =?Windows-1252?Q?KatIhPliwLCC5Pf21ESk1SU2KxaCvEv7dC6UBn+eLzt//sXOmMMt2tG4?= =?Windows-1252?Q?bwe/NzLH7Fi2yFKbS4bGWJkBLPHA+Aivuadhsne4wJuRDJlZWwjTwO0u?= =?Windows-1252?Q?QezDfZDlPEomA9bzdC+UqiDnHp8K10imf/cHIZnElOmTfUFQQhrCW5c6?= =?Windows-1252?Q?89We93K6yZYoEjJSKo/3kdIlXTc5ed6vrXIBcwr8XqXHu4suavH7Rc?= =?Windows-1252?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1;BL2PR15MB0963;6:y0HYzfGKiLTz87/XSD36X2FcuL4+YOsFp8Te/QVj2+T3BM99NouKVvAOqg/5tCF9n7M4Oe2qp36dmuSR2WShRpFLvrn31qfLIYh9z3gVeasN+8/QD/yGhXQ7k0t4jzkhv+pGnvqOaq7dvSk+z8asIKwGgTn/+CgPSy+9DHa2asye7GrN3StfWM6jamV/zVEieZGyOlw5KzC25ksNXrXXuBOLP6QASVS4dGsOKbdr+GKAanoFdKvrd4LRNWBSyTDs/bJcDB1xNk0t+PpButWH91ZMNzaERQynWN3g8KfjCT+pxFbiJ12AemnQcYZiVBIOy1KgsBEWO0VkgTG0UzC3TIjMZsiGs7bzozfXumnkv7s=;5:/p+vrhhE4ESy4MbdN9X9OfIZpR9OBSb4Jr0Led8D33L3bcSWQRktME+T4qCLgVeTUjZY7VEsGjMDBqAP2eZcoSgoF0o9kurwA0ViPYasCdND5K3qS0UViULUqWzPY+fzx5WMo/32Vvg/pmucKVbNibjHtahnENTCQ+hI21wZWDk=;24:YU+0xSXMEw238wh9RtcHi1IRJmPjrknUIQlCe/RPWoF0ktYk/6LULrboGKK9S35swl8vfTYCM6LNBuS+0ec4vz4MWQC4dl2l2SELjWVwsMU=;7:0mokEeOXUh5d7GOncALuBildgfxorySO97o+rQL8/l9Ih/96KUIjDCKsZeeOfRrK4KQE6sbI7H2d6hKeFG1zlX9K76GINoqqgr8CIeAGyOZzUc/kxs0CFbqr8AEGRCoVHNO1APsNRtBgaeX1F4TvvVCBpHPGusaml1XXZJkXcyQE8d5ny0OC3W6nP5GVjjkeP4gQ0Jp20pQ+aX2cv2xfCf0XGSIw/GotwVUVjPlRmD4i95h5sX998MzPujs4ZGOR SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BL2PR15MB0963;20:iiCx8FDpicTBB8vSviG9shkw/KoxTfZzdgjzn/e2Qjz19lU0yHqUsO3rrRvNR5nNwOLAsQgjzhr92wfRofkoohKCUNHJIig++vJpOpgWsijhYNW8lm9GDpFMFBPBadc3vNWYfl/E//GiGUGVggVmxO0Zsw/3zZx+yikCKG7tSPk= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Dec 2017 17:33:17.7658 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8114ffe7-47ba-4658-69ad-08d547cfc2f1 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR15MB0963 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-12-20_07:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3805 Lines: 99 On 12/20/17 3:00 AM, Masami Hiramatsu wrote: > On Fri, 15 Dec 2017 14:12:52 -0500 > Josef Bacik wrote: > >> From: Josef Bacik >> >> Using BPF we can override kprob'ed functions and return arbitrary >> values. Obviously this can be a bit unsafe, so make this feature opt-in >> for functions. Simply tag a function with KPROBE_ERROR_INJECT_SYMBOL in >> order to give BPF access to that function for error injection purposes. >> >> Signed-off-by: Josef Bacik >> Acked-by: Ingo Molnar >> --- >> include/asm-generic/vmlinux.lds.h | 10 +++ >> include/linux/bpf.h | 11 +++ >> include/linux/kprobes.h | 1 + >> include/linux/module.h | 5 ++ >> kernel/kprobes.c | 163 ++++++++++++++++++++++++++++++++++++++ >> kernel/module.c | 6 +- >> 6 files changed, 195 insertions(+), 1 deletion(-) >> >> diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h >> index ee8b707d9fa9..a2e8582d094a 100644 >> --- a/include/asm-generic/vmlinux.lds.h >> +++ b/include/asm-generic/vmlinux.lds.h >> @@ -136,6 +136,15 @@ >> #define KPROBE_BLACKLIST() >> #endif >> >> +#ifdef CONFIG_BPF_KPROBE_OVERRIDE >> +#define ERROR_INJECT_LIST() . = ALIGN(8); \ >> + VMLINUX_SYMBOL(__start_kprobe_error_inject_list) = .; \ >> + KEEP(*(_kprobe_error_inject_list)) \ >> + VMLINUX_SYMBOL(__stop_kprobe_error_inject_list) = .; >> +#else >> +#define ERROR_INJECT_LIST() >> +#endif >> + >> #ifdef CONFIG_EVENT_TRACING >> #define FTRACE_EVENTS() . = ALIGN(8); \ >> VMLINUX_SYMBOL(__start_ftrace_events) = .; \ >> @@ -564,6 +573,7 @@ >> FTRACE_EVENTS() \ >> TRACE_SYSCALLS() \ >> KPROBE_BLACKLIST() \ >> + ERROR_INJECT_LIST() \ >> MEM_DISCARD(init.rodata) \ >> CLK_OF_TABLES() \ >> RESERVEDMEM_OF_TABLES() \ >> diff --git a/include/linux/bpf.h b/include/linux/bpf.h >> index e55e4255a210..7f4d2a953173 100644 >> --- a/include/linux/bpf.h >> +++ b/include/linux/bpf.h >> @@ -576,4 +576,15 @@ extern const struct bpf_func_proto bpf_sock_map_update_proto; >> void bpf_user_rnd_init_once(void); >> u64 bpf_user_rnd_u32(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5); >> >> +#if defined(__KERNEL__) && !defined(__ASSEMBLY__) >> +#ifdef CONFIG_BPF_KPROBE_OVERRIDE >> +#define BPF_ALLOW_ERROR_INJECTION(fname) \ >> +static unsigned long __used \ >> + __attribute__((__section__("_kprobe_error_inject_list"))) \ >> + _eil_addr_##fname = (unsigned long)fname; >> +#else >> +#define BPF_ALLOW_ERROR_INJECTION(fname) >> +#endif >> +#endif > > This part shows this feature belongs to bpf, if it is a part of kprobes, > it should be defined in include/asm-generic/kprobes.h as NOKPROBE_SYMBOL > does. > > Why this is defined in BPF, but list is under kprobes? because Ingo specifically requested that macro that marks the function will be in bpf.h, so any .c file that starts adding such marks will include that file instead of pulling stuff from kprobe. > > So there is no direct relationship with kprobe. > For example, kprobe user modules can OVERRIDE any functions. > And there is no generic error injection code in the kernel > except for the bpf currently. _currently_ is key word. > Of course, I can accept this code if you accept that I make a > generic error injection code on ftrace without BPF. what stops other pieces of kernel to use the same technique? The bpf verifier coupled together with opt-in per-function marks via BPF_ALLOW_ERROR_INJECTION give _safe_ way to do error injection. I can imagine how you can hack kprobe text based interface to use the same technique, but I suggest to wait and see how we build on it in bpf land before replicating things in pure kprobe land.