Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp409430pxu; Tue, 1 Dec 2020 14:33:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJyguvZBirLE4SFloc37at0rlNcCC1vqBrnbkYxmzdSfiI7y6FHPAerzOUu+lVEmNV2NJUIC X-Received: by 2002:a50:d90c:: with SMTP id t12mr3825078edj.231.1606861997240; Tue, 01 Dec 2020 14:33:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606861997; cv=none; d=google.com; s=arc-20160816; b=stlUbWZD7wW/CRF+j2+XbW1dUiIcmtn6IdqA69ey2G7c6bsCxyF47ChrtkV1H1Frmg 6qnQ1EwP4iNKlVh+vX77AboIkNzdTjM8uBPDffsGaCqYjhu6ETX/mBRzUpO7ubiDavhG HyRij/v0ecjbjU4F9/nDkCNM+B6d2zuaf5DWHecLbDEtjYFVgHMoDLYbJuo8+7S37Qko 9U6dwup9ymFFMkMMTWWnZjfuQaab6iBSTX1RMzhYE416r3qiAjgeJFrj++2k86LiG8qZ l4zyIulLb+Cf4jSHa3c/LEe8Lw34LU2AeK1XOtRFV4e2ds6X1IU+43wPkb+/WoOrw8L8 GGJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1WrVeWaV61mLPrAxdBqx4yEN2cNDo0MgMuijjZY9sSM=; b=CwcPF/Fp+O/l63i+dlKNvRzKoF+9dTj1q8UXJRkgnATEsNlbtn1bXCb4GGkavfY0Yv DYxViU07YyilkEkC3vOcvIscB2U4P9Q8ziDlgt12NXrFjWzBy+XvlqBVdXlkVEKI59aW 4u1PbJaatLu2OkhL9TTfiicf8VWe1WZ9DJ5xuasUMq93GeGdVWxpp1uUU9uyyKS48w5D CytuVKQqeIVM6ajZxD9rvNj0VbXNxsAC7gziWZlOpFiIehQied5PkwK34nbLzbeESvlt 9qPhIkS052/15zbJOjak6KtRct2Z8Fkl0EgIeZS23D9jMNyrxc7biPCdqUu7Xsv9qb3/ FwRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=p61OTGK7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id de12si771362edb.38.2020.12.01.14.32.54; Tue, 01 Dec 2020 14:33:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=p61OTGK7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390843AbgLAJYe (ORCPT + 99 others); Tue, 1 Dec 2020 04:24:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:42722 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388206AbgLAJFz (ORCPT ); Tue, 1 Dec 2020 04:05:55 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 024E521D7A; Tue, 1 Dec 2020 09:05:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606813514; bh=QAD19RwmOeK50zl3uL/i9chrctMGIBGRWAy7HvaDjn4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p61OTGK7jRUnzAfe/0lJwarW5v2H9+vTeFOlwz/1JHHVG6QFopY9K0bt8YDEeCWv3 rAZeNi0+wiv/8SC1mrmx7YtmERDc1zRcg/vTmIrkKAIxBI64gQ204BYgWf8h0h1F9E enC3bhTnQ0a9fcHyLk73kFMtD+X4NqiWx2zwdYEU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lijun Pan , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.4 66/98] ibmvnic: fix NULL pointer dereference in ibmvic_reset_crq Date: Tue, 1 Dec 2020 09:53:43 +0100 Message-Id: <20201201084658.314368538@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084652.827177826@linuxfoundation.org> References: <20201201084652.827177826@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lijun Pan [ Upstream commit 0e435befaea45f7ea58682eecab5e37e05b2ce65 ] crq->msgs could be NULL if the previous reset did not complete after freeing crq->msgs. Check for NULL before dereferencing them. Snippet of call trace: ... ibmvnic 30000003 env3 (unregistering): Releasing sub-CRQ ibmvnic 30000003 env3 (unregistering): Releasing CRQ BUG: Kernel NULL pointer dereference on read at 0x00000000 Faulting instruction address: 0xc0000000000c1a30 Oops: Kernel access of bad area, sig: 11 [#1] LE PAGE_SIZE=64K MMU=Hash SMP NR_CPUS=2048 NUMA pSeries Modules linked in: ibmvnic(E-) rpadlpar_io rpaphp xt_CHECKSUM xt_MASQUERADE xt_conntrack ipt_REJECT nf_reject_ipv4 nft_compat nft_counter nft_chain_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 nf_tables xsk_diag tcp_diag udp_diag tun raw_diag inet_diag unix_diag bridge af_packet_diag netlink_diag stp llc rfkill sunrpc pseries_rng xts vmx_crypto uio_pdrv_genirq uio binfmt_misc ip_tables xfs libcrc32c sd_mod t10_pi sg ibmvscsi ibmveth scsi_transport_srp dm_mirror dm_region_hash dm_log dm_mod [last unloaded: ibmvnic] CPU: 20 PID: 8426 Comm: kworker/20:0 Tainted: G E 5.10.0-rc1+ #12 Workqueue: events __ibmvnic_reset [ibmvnic] NIP: c0000000000c1a30 LR: c008000001b00c18 CTR: 0000000000000400 REGS: c00000000d05b7a0 TRAP: 0380 Tainted: G E (5.10.0-rc1+) MSR: 800000000280b033 CR: 44002480 XER: 20040000 CFAR: c0000000000c19ec IRQMASK: 0 GPR00: 0000000000000400 c00000000d05ba30 c008000001b17c00 0000000000000000 GPR04: 0000000000000000 0000000000000000 0000000000000000 00000000000001e2 GPR08: 000000000001f400 ffffffffffffd950 0000000000000000 c008000001b0b280 GPR12: c0000000000c19c8 c00000001ec72e00 c00000000019a778 c00000002647b440 GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 GPR20: 0000000000000006 0000000000000001 0000000000000003 0000000000000002 GPR24: 0000000000001000 c008000001b0d570 0000000000000005 c00000007ab5d550 GPR28: c00000007ab5c000 c000000032fcf848 c00000007ab5cc00 c000000032fcf800 NIP [c0000000000c1a30] memset+0x68/0x104 LR [c008000001b00c18] ibmvnic_reset_crq+0x70/0x110 [ibmvnic] Call Trace: [c00000000d05ba30] [0000000000000800] 0x800 (unreliable) [c00000000d05bab0] [c008000001b0a930] do_reset.isra.40+0x224/0x634 [ibmvnic] [c00000000d05bb80] [c008000001b08574] __ibmvnic_reset+0x17c/0x3c0 [ibmvnic] [c00000000d05bc50] [c00000000018d9ac] process_one_work+0x2cc/0x800 [c00000000d05bd20] [c00000000018df58] worker_thread+0x78/0x520 [c00000000d05bdb0] [c00000000019a934] kthread+0x1c4/0x1d0 [c00000000d05be20] [c00000000000d5d0] ret_from_kernel_thread+0x5c/0x6c Fixes: 032c5e82847a ("Driver for IBM System i/p VNIC protocol") Signed-off-by: Lijun Pan Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/ibm/ibmvnic.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c index 238915410d79a..e53994ca3142c 100644 --- a/drivers/net/ethernet/ibm/ibmvnic.c +++ b/drivers/net/ethernet/ibm/ibmvnic.c @@ -4777,6 +4777,9 @@ static int ibmvnic_reset_crq(struct ibmvnic_adapter *adapter) } while (rc == H_BUSY || H_IS_LONG_BUSY(rc)); /* Clean out the queue */ + if (!crq->msgs) + return -EINVAL; + memset(crq->msgs, 0, PAGE_SIZE); crq->cur = 0; crq->active = false; -- 2.27.0