Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp316829pxa; Thu, 27 Aug 2020 03:13:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+V8gMcT5ebY1SuyAY5AS1V551vLc+z72g/7xPFdxp9Gq+4z1sexHikjkT0m+Pp8GWPso9 X-Received: by 2002:aa7:d912:: with SMTP id a18mr11004829edr.18.1598523211642; Thu, 27 Aug 2020 03:13:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598523211; cv=none; d=google.com; s=arc-20160816; b=VffwpmbLYQoXnvgm5bTnR5iko9AHdad2SpdkbmI2cdoIlquZUXxvjOFTgksZYrOJpc v5O7oXlB34INV/22iMWnhr/HkM50chTbJNkRXc8HV88egHwLU9DKkOBQ9DBD731BDbua QYc/fG+5iXnlK9DYPKrWfwi+UbB/0SE2Zk9MBCnwC8tJUa2+zXHFTWL1JribO60mY4pu LG6Xv0gI3aAwIPqhcva1DrMQfExZQQJjqGhaQsWMeUHxGX9Wy6MyVnVPG+DIaJm2KVlU H2bo3NlB9tdxpgndd35reaow6nlHhA4Pgsjmr1cKqGAiQJFe4MCoHcoYEKTau0gs8Moa 6AcQ== 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:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=3xXgryl2zRPGkLYAw9dVTy6qSkt1prrLZlh8olisSKA=; b=gUCcM8qmkhBJ6zufo1UaFwq941HwWnl6wJDIKPhofkf3BRyItmY/hkc+IObMLqN6og 5tK4MGMlSn7RZw0Cm74sZxYZSYwPYVOAQ1j008vL+IKJkjmuxN153fOb3CAsRFf/JEZV eX6wsz9YVnaNEPDZKgiA58gqJqY88NHWKOQVowIDC5LHStIYYL3chMdQuoN3erj35Jw0 jE4ZnCk6dHXeIRHp/yjOoHdgpCjq/OQGqQDoImr8tI0ZOwaG22x35hbzCXprC7wmb08j 8yPI9Gp38dixJDFDVYPscag0hXdGXBFFenOfkEcLWZ68SXfzQHXUUl1yD8h8fxQq91y8 /FXg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g12si1186511edu.135.2020.08.27.03.13.09; Thu, 27 Aug 2020 03:13:31 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728474AbgH0KMG (ORCPT + 99 others); Thu, 27 Aug 2020 06:12:06 -0400 Received: from mx2.suse.de ([195.135.220.15]:54450 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726157AbgH0KMG (ORCPT ); Thu, 27 Aug 2020 06:12:06 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D8C55AC2F; Thu, 27 Aug 2020 10:12:36 +0000 (UTC) Message-ID: <04f76144372753cceab48f59f7f2aaea017f021f.camel@suse.com> Subject: Re: [PATCH 1/4] qla2xxx: Reset done and free callback pointer on release From: Martin Wilck To: Daniel Wagner , linux-scsi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nilesh Javali Date: Thu, 27 Aug 2020 12:12:04 +0200 In-Reply-To: <20200827095829.63871-2-dwagner@suse.de> References: <20200827095829.63871-1-dwagner@suse.de> <20200827095829.63871-2-dwagner@suse.de> Content-Type: text/plain; charset="ISO-8859-15" User-Agent: Evolution 3.36.5 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2020-08-27 at 11:58 +0200, Daniel Wagner wrote: > Reset ->done and ->free when releasing the srb. There is a hidden > use-after-free bug in the driver which corrupts the srb memory pool > which originates from the cleanup callbacks. By explicitly resetting > the callbacks to NULL, we workaround the memory corruption. > > An extensive search didn't bring any lights on the real problem. The > initial idea 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. > > Signed-off-by: Daniel Wagner > --- > drivers/scsi/qla2xxx/qla_inline.h | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/scsi/qla2xxx/qla_inline.h > b/drivers/scsi/qla2xxx/qla_inline.h > index 861dc522723c..6d41d758fc17 100644 > --- a/drivers/scsi/qla2xxx/qla_inline.h > +++ b/drivers/scsi/qla2xxx/qla_inline.h > @@ -211,6 +211,8 @@ static inline void > qla2xxx_rel_qpair_sp(struct qla_qpair *qpair, srb_t *sp) > { > sp->qpair = NULL; > + sp->done = NULL; > + sp->free = NULL; > mempool_free(sp, qpair->srb_mempool); > QLA_QPAIR_MARK_NOT_BUSY(qpair); > } Both sp->done() and sp->free() are called all over the place without making sure the pointers are non-null. If these functions can be called for freed sp's, wouldn't that mean we'd crash? How about setting them to a dummy function that prints a big fat warning? Martin