Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp563240img; Thu, 21 Mar 2019 04:22:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqwVAUBUWMoAU7/Isal9u/PRcboLM5+G+x/xaCNKTjmVMjt1QRhUFS3PPQ/Nth1MyuwRbviD X-Received: by 2002:a62:1b84:: with SMTP id b126mr2708478pfb.225.1553167363090; Thu, 21 Mar 2019 04:22:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553167363; cv=none; d=google.com; s=arc-20160816; b=eCBjdpJqW2uk3i38xQUiQK1bZiCOdR7e8XLiU2DIuS0vnelUAOYFlAs5hp2yLwxbct 7zUg2vga23rysiZN8YSf+KO82XCInBxbQLZWSq9ZwT1Mp+amYbrLeirPbJ7sliwXIkas NFNK7QeqbLWaF8sAJ3ApM5ljGOdOS7AVFD+CPr+M4z/9XJi2x/uewbEt9h+FfQMUzsHT Xbh/tvE3MxLdAU7ht33skytFXykhdThc6RHg9tNz/ahSPe3e6OeX+2OxHXcDdAT9RxqK jSFS61cJOieLFiBRuVS/WwdxmDkcMmXK2tJtpZ/c6am+BDQfxCu7pBZIqGv7neNJzXQn ltcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject; bh=XUWM+xNHrHW37PeLgGEkIsit1ahSNhNOTS0w9LBiJj8=; b=PNGaKEGPyIShV02SkOKdJpBY6+xeh6dzbun7rXxTa6WaPlFc3q+b1eDoQz1gTvA2zq pm+SVjIld3W+feP0wLr6W4iuWOLex/pVVZxFdPGfAhcvSdLatniDgpOJiMHJ0Aeguqks UaygPPVCccdzgQt2VxPZcnnpgBP/QTEstViIlB8YP4il13TUR/FSo2zk4h9XY1Jo+9Q/ vzLG6WC1IAYxRYvkljwBWrO3USPTuOuqrf/Ppn/h8WtlqvGWRqymcCn65h3sJMLl0+Ff y4qUKXX2fM/fjeKdXkI+9mSHadcYublxoKGQ6PyLBCysA1l+3Cukibc0pj9mFGAGCSKj KZhA== ARC-Authentication-Results: i=1; mx.google.com; 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 91si4262357pla.14.2019.03.21.04.22.25; Thu, 21 Mar 2019 04:22:43 -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; 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 S1727949AbfCULVd (ORCPT + 99 others); Thu, 21 Mar 2019 07:21:33 -0400 Received: from www62.your-server.de ([213.133.104.62]:60962 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727823AbfCULVd (ORCPT ); Thu, 21 Mar 2019 07:21:33 -0400 Received: from [88.198.220.132] (helo=sslproxy03.your-server.de) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1h6vlK-0002DL-Tp; Thu, 21 Mar 2019 12:21:31 +0100 Received: from [178.197.248.24] (helo=linux.home) by sslproxy03.your-server.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1h6vlK-0005Ow-L2; Thu, 21 Mar 2019 12:21:30 +0100 Subject: Re: [PATCH v2] bpf: do not restore dst_reg when cur_state is freed To: Xu Yu , bpf@vger.kernel.org, linux-kernel@vger.kernel.org References: From: Daniel Borkmann Message-ID: Date: Thu, 21 Mar 2019 12:21:29 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.100.2/25395/Thu Mar 21 08:52:58 2019) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/21/2019 11:00 AM, Xu Yu wrote: > Syzkaller hit 'KASAN: use-after-free Write in sanitize_ptr_alu' bug. > Call trace: > dump_stack+0xbf/0x12e > print_address_description+0x6a/0x280 > kasan_report+0x237/0x360 > sanitize_ptr_alu+0x85a/0x8d0 > adjust_ptr_min_max_vals+0x8f2/0x1ca0 > adjust_reg_min_max_vals+0x8ed/0x22e0 > do_check+0x1ca6/0x5d00 > bpf_check+0x9ca/0x2570 > bpf_prog_load+0xc91/0x1030 > __se_sys_bpf+0x61e/0x1f00 > do_syscall_64+0xc8/0x550 > entry_SYSCALL_64_after_hwframe+0x49/0xbe > Fault injection trace: >  kfree+0xea/0x290 >  free_func_state+0x4a/0x60 >  free_verifier_state+0x61/0xe0 >  push_stack+0x216/0x2f0 <- inject failslab >  sanitize_ptr_alu+0x2b1/0x8d0 >  adjust_ptr_min_max_vals+0x8f2/0x1ca0 >  adjust_reg_min_max_vals+0x8ed/0x22e0 >  do_check+0x1ca6/0x5d00 >  bpf_check+0x9ca/0x2570 >  bpf_prog_load+0xc91/0x1030 >  __se_sys_bpf+0x61e/0x1f00 >  do_syscall_64+0xc8/0x550 >  entry_SYSCALL_64_after_hwframe+0x49/0xbe > > When kzalloc() fails in push_stack(), free_verifier_state() will free > current verifier state. As push_stack() returns, dst_reg was restored > if ptr_is_dst_reg is false. However, as member of the cur_state, dst_reg > is also freed, and error occurs when dereferencing dst_reg. > > Simply fix it by testing ret of push_stack() before retoring dst_reg. > > Signed-off-by: Xu Yu Applied, thanks!