Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp245023pxx; Wed, 28 Oct 2020 03:59:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrmKSRRQIGh1SXqec2q2OiDLUXalTUHx3PzZHosiePyB8n5od8N2tX/tJz1Ces1eEk8Zz2 X-Received: by 2002:a05:6402:1585:: with SMTP id c5mr7186556edv.278.1603882741804; Wed, 28 Oct 2020 03:59:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603882741; cv=none; d=google.com; s=arc-20160816; b=W3P7YieP8I+VMOI98DvLilIobQONDI7lpWyugwoD8ILhiiDh4ZxqnU1b7e3ymQg5J+ v0U7n4xXXgWxmWwexxPhGn5p3wvdLwemerUQnsaS7lMVcYRmNDZ9GIyu2wq9zH7Pkdu3 t14mfSoGRqzgEoq3KG7IwxFD8YX2CXFART8T0+jFJ8VA7WHQlZcxakmaU8h6tgGpiHI6 Lk9Vb5oIzV2vcLNWEivjfuoZkuBjpBv5k3++DAeTPfEEG8idg0FOt+ys3r1duQGloIHP x/b6XEcdXXaAjbTZR8/YVetrxGjaHULJf6wqYhRhuQDBzMzb8dZJZ9/ncKzjpZdPBj5d saZg== 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=PDnb02Pc171We1HFvteeJ3reFB3HXnDIp73WZtMubhA=; b=wA0j5fs2hSMyi/tOWztsIA9/N+153rt//oEwSxZuaTyvkBlChbRt/CbBxW+U/AjyJb X5R4IRzmSM3oKah3WMexG8b4AZtMyCVwZH0MRWvy4ExWi3aL1ux4E8IfgqMQiJvJcQP8 RbSZAQyqek+4Vw3nppyBw4f/mrE1kLhAb4K6bDfScdqbz6b5W4c+oMInNcDhD2BqLLV1 aoX9dAOn+ZYjkMeGzDmZloQchfK4HRaMAxXczKv9LvflFIA6ZrZtPKZxF1sxWppiq0ZR PoQNbhPoaYl6KV+TJA18QssvBpAeI6vqQBbzfZG5MjHzUI/NYvoONUSKxk3eoPXet2hS slRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gk3hdpZY; 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=fail (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 x26si2664388eds.99.2020.10.28.03.58.39; Wed, 28 Oct 2020 03:59:01 -0700 (PDT) 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=@kernel.org header.s=default header.b=gk3hdpZY; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1782620AbgJ0O5P (ORCPT + 99 others); Tue, 27 Oct 2020 10:57:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:45818 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1763994AbgJ0Opy (ORCPT ); Tue, 27 Oct 2020 10:45:54 -0400 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 2854C2225E; Tue, 27 Oct 2020 14:45:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809952; bh=/98Zb1vLk8D8gEKuqdCgRdpe9G2AWlck9qCBGmPL38k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gk3hdpZYpIsbyH2hBnZEi+ryV7lcCMPV2lOaZuOKjgQ9uQVXp8LT5e1mVU1flBFXW 8gcx51iFGjzD89xxYKQGFEcUucU6eUhQcmmJa7L4FOTrCGO5J0jg7rJScl6FZnSVwm oohqTvNjYqkrt4CvZ9TfBVlHaxlh557y+aq+FVd0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Martin Wilck , Arun Easi , Daniel Wagner , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.4 376/408] scsi: qla2xxx: Warn if done() or free() are called on an already freed srb Date: Tue, 27 Oct 2020 14:55:14 +0100 Message-Id: <20201027135512.450377381@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@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: Daniel Wagner [ Upstream commit c0014f94218ea3a312f6235febea0d626c5f2154 ] Emit a warning when ->done or ->free are called on an already freed srb. There is a hidden use-after-free bug in the driver which corrupts the srb memory pool which originates from the cleanup callbacks. An extensive search didn't bring any lights on the real problem. The initial fix was to set both pointers to NULL and try to catch invalid accesses. But instead the memory corruption was gone and the driver didn't crash. Since not all calling places check for NULL pointer, add explicitly default handlers. With this we workaround the memory corruption and add a debug help. Link: https://lore.kernel.org/r/20200908081516.8561-2-dwagner@suse.de Reviewed-by: Martin Wilck Reviewed-by: Arun Easi Signed-off-by: Daniel Wagner Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/qla2xxx/qla_init.c | 10 ++++++++++ drivers/scsi/qla2xxx/qla_inline.h | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c index 62d2ee825c97a..b300e11095828 100644 --- a/drivers/scsi/qla2xxx/qla_init.c +++ b/drivers/scsi/qla2xxx/qla_init.c @@ -71,6 +71,16 @@ void qla2x00_sp_free(srb_t *sp) qla2x00_rel_sp(sp); } +void qla2xxx_rel_done_warning(srb_t *sp, int res) +{ + WARN_ONCE(1, "Calling done() of an already freed srb %p object\n", sp); +} + +void qla2xxx_rel_free_warning(srb_t *sp) +{ + WARN_ONCE(1, "Calling free() of an already freed srb %p object\n", sp); +} + /* Asynchronous Login/Logout Routines -------------------------------------- */ unsigned long diff --git a/drivers/scsi/qla2xxx/qla_inline.h b/drivers/scsi/qla2xxx/qla_inline.h index 0c3d907af7692..6dfde42d799b5 100644 --- a/drivers/scsi/qla2xxx/qla_inline.h +++ b/drivers/scsi/qla2xxx/qla_inline.h @@ -183,10 +183,15 @@ qla2xxx_get_qpair_sp(scsi_qla_host_t *vha, struct qla_qpair *qpair, return sp; } +void qla2xxx_rel_done_warning(srb_t *sp, int res); +void qla2xxx_rel_free_warning(srb_t *sp); + static inline void qla2xxx_rel_qpair_sp(struct qla_qpair *qpair, srb_t *sp) { sp->qpair = NULL; + sp->done = qla2xxx_rel_done_warning; + sp->free = qla2xxx_rel_free_warning; mempool_free(sp, qpair->srb_mempool); QLA_QPAIR_MARK_NOT_BUSY(qpair); } -- 2.25.1