Received: by 10.213.65.68 with SMTP id h4csp36420imn; Mon, 19 Mar 2018 18:43:42 -0700 (PDT) X-Google-Smtp-Source: AG47ELsflvb86O7KJxvtHx+NNHbiObpeatrjppV6jTdDTgpW/PnNyoxeI8YGEUNYIwnucY5gg5Wk X-Received: by 2002:a17:902:2f:: with SMTP id 44-v6mr14675069pla.187.1521510222159; Mon, 19 Mar 2018 18:43:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521510222; cv=none; d=google.com; s=arc-20160816; b=EDmXBzTxQv0mTL6jpLAzzg8CwPaUn425KL9bfwPxnp+WIKR/fKkGJE5o3wP4+8zZL1 E5ltYTqMp9zkQNdu7CIewPLwZ5ZYouipiBVBBASFCMAWIk7skkEICR5VGMycXKZgjeHM QmYH7SWeJWlH2AtR1aDwhflzOpSc+00dCYHX3/EatEMRJFvAQdopiegmUSsABbbOjtQA ACZmyK3VYiWpLEyhHmR37hUnYBbTFXU/9SqOR/6i0c/ldZ7CwhSSfYlom9WaJb97cua/ RSZGv0vVQ9JZK2/6m+U/lIjc5y5BvdZHxMetDG0OQ4fXHb6TzawMNsGtuRyAb7N5/zzW Uv8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=iqNy3hbY0JT6cf6Y3ZWl9GG5kfDHegGjKtiWF5bajcw=; b=fee1/jfxadq01PY9+WX8U379cpCvaDo/ymjw9KBc/Jlad0tZhOq4u9boAM7rNXllmL oZLGNqKKqe0VLlZABiWz9mOK276wePQJk6nHWY6yRGn3kaMgY90CEEj1bWLYGXDWnEKc LWOio/vvRbKpXPrAq5jCjUFtZxXrMGlJoyXGmh8IewJOKsK8TnJv85slZZwAWCCc2lkE INR+LaGiFOV3K1lheTfMXO42oXoQoPxOSeBxcy9rj4WCtJn7XAh70HH0r8Wo9e7cKeCn 4EHpsGRnypvYimYiXU/+38sfLRAcbdrC6WSLpEiTkHOPRu+a5C6QQoisPmzuTFJ9Gyco 0Dhg== 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 q26si431227pfh.129.2018.03.19.18.43.28; Mon, 19 Mar 2018 18:43:42 -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 S1030810AbeCSSQ3 (ORCPT + 99 others); Mon, 19 Mar 2018 14:16:29 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45066 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S968750AbeCSSQR (ORCPT ); Mon, 19 Mar 2018 14:16:17 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 4DD011229; Mon, 19 Mar 2018 18:16:16 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , Hannes Reinecke , Johannes Thumshirn , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.4 074/134] scsi: sg: close race condition in sg_remove_sfp_usercontext() Date: Mon, 19 Mar 2018 19:05:57 +0100 Message-Id: <20180319171859.944040060@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319171849.024066323@linuxfoundation.org> References: <20180319171849.024066323@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Hannes Reinecke [ Upstream commit 97d27b0dd015e980ade63fda111fd1353276e28b ] sg_remove_sfp_usercontext() is clearing any sg requests, but needs to take 'rq_list_lock' when modifying the list. Reported-by: Christoph Hellwig Signed-off-by: Hannes Reinecke Reviewed-by: Johannes Thumshirn Tested-by: Johannes Thumshirn Reviewed-by: Christoph Hellwig Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/sg.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -535,6 +535,7 @@ sg_read(struct file *filp, char __user * } else count = (old_hdr->result == 0) ? 0 : -EIO; sg_finish_rem_req(srp); + sg_remove_request(sfp, srp); retval = count; free_old_hdr: kfree(old_hdr); @@ -575,6 +576,7 @@ sg_new_read(Sg_fd * sfp, char __user *bu } err_out: err2 = sg_finish_rem_req(srp); + sg_remove_request(sfp, srp); return err ? : err2 ? : count; } @@ -811,6 +813,7 @@ sg_common_write(Sg_fd * sfp, Sg_request SCSI_LOG_TIMEOUT(1, sg_printk(KERN_INFO, sfp->parentdp, "sg_common_write: start_req err=%d\n", k)); sg_finish_rem_req(srp); + sg_remove_request(sfp, srp); return k; /* probably out of space --> ENOMEM */ } if (atomic_read(&sdp->detaching)) { @@ -823,6 +826,7 @@ sg_common_write(Sg_fd * sfp, Sg_request } sg_finish_rem_req(srp); + sg_remove_request(sfp, srp); return -ENODEV; } @@ -1312,6 +1316,7 @@ sg_rq_end_io_usercontext(struct work_str struct sg_fd *sfp = srp->parentfp; sg_finish_rem_req(srp); + sg_remove_request(sfp, srp); kref_put(&sfp->f_ref, sg_remove_sfp); } @@ -1856,8 +1861,6 @@ sg_finish_rem_req(Sg_request *srp) else sg_remove_scat(sfp, req_schp); - sg_remove_request(sfp, srp); - return ret; } @@ -2204,12 +2207,17 @@ sg_remove_sfp_usercontext(struct work_st struct sg_fd *sfp = container_of(work, struct sg_fd, ew.work); struct sg_device *sdp = sfp->parentdp; Sg_request *srp; + unsigned long iflags; /* Cleanup any responses which were never read(). */ + write_lock_irqsave(&sfp->rq_list_lock, iflags); while (!list_empty(&sfp->rq_list)) { srp = list_first_entry(&sfp->rq_list, Sg_request, entry); sg_finish_rem_req(srp); + list_del(&srp->entry); + srp->parentfp = NULL; } + write_unlock_irqrestore(&sfp->rq_list_lock, iflags); if (sfp->reserve.bufflen > 0) { SCSI_LOG_TIMEOUT(6, sg_printk(KERN_INFO, sdp,