Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp409326pxu; Tue, 1 Dec 2020 14:33:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4rK/g0vXUxHD5dB2CMRh9gwl0bZb+Sfk25swAOFxbRJmVUyt+x58rBmSEcXZDuM6KzAa/ X-Received: by 2002:aa7:d7d7:: with SMTP id e23mr5533227eds.78.1606861985200; Tue, 01 Dec 2020 14:33:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606861985; cv=none; d=google.com; s=arc-20160816; b=O4YnjHTR4p/ieR3yf7T+Gl1GbGDu3pRtKqNG5qYEjRXBT95IchKohKMN62C6atKpE3 7J/v2+hrqAaLIF3KTFgB/CSeieM1vN0AuZzluVwYAfgqMezA53CNn0Rm7R4PmGLRHi7B SgxVDdkU853CWgeCOfdIARcRyvn0wWPtNyaFmlVVXd6TrAKqVLJKjHYxHLlBRAYXRNqu 90KaCu8ivpFYEkpDMR0thuHo+gxROJ7fMr8JefIkPRRnnvUrU+RlBLoxnIisAnjo0m3M aLyVMbqgMAeJaZDCpp1ZIBXFtg9yPoZ9+uhVCNeWIPatm3oLUa1NqfzDqB9Eww6hUK4V IKyQ== 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=YXoyTidkmpy4YAXHjYWqQRFPQDZOHE5tAQzpxbCavM0=; b=ZeWZ9xM1vUvu9U5q/HDhNIlq82TnVNZ14g8SK4GKMS6SMzHVBdexQXDpzrWGOv//yo j2PvIwVISWau5PJt/N1TkjeCu09ucmVdHkknKo6HKhcxVI+JqYZKZ+ny0cDy/tIK6YEI O3fEdWHJ9CealIAl1B7yYUMQZ+tKzSxsolBXmyofC/tncbUu0VYxFRT5mHjRvWCDKR03 f2j06U8sgBMDVKrOlEN5KeyQJOYU5jqujSG1s/AwvgYUQqOTOZaz7t95MdDV9AhTQq9X YzxsIN7+XCGbB/NauGaJfN0przzuZWa/bn7nyQJwKZmppAB70wR1GtZMICJ/J47SbQPR UbNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TuBmyBUW; 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 f8si840142ejc.50.2020.12.01.14.32.42; Tue, 01 Dec 2020 14:33:05 -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=TuBmyBUW; 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 S2391185AbgLAJaA (ORCPT + 99 others); Tue, 1 Dec 2020 04:30:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:33962 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387996AbgLAI6q (ORCPT ); Tue, 1 Dec 2020 03:58:46 -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 23667217A0; Tue, 1 Dec 2020 08:58:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606813110; bh=O+D1R/pFw8gXaEdV01ch5sUSh8dZ6jxll7Pruf83LAg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TuBmyBUW49XqPVXEO3ljcg17s/t38ikd4SkUfL0/N6wIpCcpQuR1Zt8PFBAI+y29o vZ5pozqrmggakAScq4qNAS6W/2lAtIwUE7X/gAiMS0Ol4IMKEI3GClGSi2RgQf43NC p1sHrwef1/dU1aWi3HsF5REhvYCiHzNazASlj4hM= 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 4.14 37/50] ibmvnic: fix NULL pointer dereference in ibmvic_reset_crq Date: Tue, 1 Dec 2020 09:53:36 +0100 Message-Id: <20201201084649.611308905@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084644.803812112@linuxfoundation.org> References: <20201201084644.803812112@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 3f2816af7b250..9a524b0e3e7ba 100644 --- a/drivers/net/ethernet/ibm/ibmvnic.c +++ b/drivers/net/ethernet/ibm/ibmvnic.c @@ -3712,6 +3712,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; -- 2.27.0