From patchwork Mon Oct 1 16:15:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evan Green X-Patchwork-Id: 10622411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E9F9113BB for ; Mon, 1 Oct 2018 16:16:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE4A929403 for ; Mon, 1 Oct 2018 16:16:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C235D2955D; Mon, 1 Oct 2018 16:16:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F28B29403 for ; Mon, 1 Oct 2018 16:16:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726174AbeJAWye (ORCPT ); Mon, 1 Oct 2018 18:54:34 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:37754 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725906AbeJAWye (ORCPT ); Mon, 1 Oct 2018 18:54:34 -0400 Received: by mail-pg1-f195.google.com with SMTP id c10-v6so9817169pgq.4 for ; Mon, 01 Oct 2018 09:16:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=JhPWD9GmCa144jbwu47jO4XGHQrL4gXGJ7XlYinBJQI=; b=l9ZTghbA4NsPDl7HANztX5eg5U8udL8CE5yi/0UxfLpAakMkdRN7ZqtSS1Vytat2i6 HMyCRoevPNwYNu+kt2J5BI+ebx5P9LUckDZST3RLT7ZvNGfPKmFXIrfXHbcmOoZgbjTI LlyYR6qAJkyBQe+4dSZ17cV3zjyIoic6ubByA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=JhPWD9GmCa144jbwu47jO4XGHQrL4gXGJ7XlYinBJQI=; b=spxbG20MLdica3CH8EidpSjW82BSgjBctHzBMichYzgVi7OCj/o9NsGqrh47aghoUN hzMgmf87PS1Kqzo62h2vd7Hs59SSBhiphN1cxjiwXReqGaBKpp4If7x04Ulky6v9VMlj kLK5x2r/3j2IAUC3x1WwnK5xgz9DKurDu9o2tvIgBD0XxAHCI9PTtWyx/VhBfSPc9QjV 4BoDb3y5jduguJ08vDiICtyuXhdYrgRNmnHxAaEDExVvomF1qije9m0KjD8cTkEkuh3q mbGilDXf+dbVp/x60FG6+IxqtkcvdF8stNX2z7aMqPp6eac8rv5q2EM9aJQJFaS0dEgs HYLQ== X-Gm-Message-State: ABuFfojIMq/d2VWKYDQO0qIMQWxvuEWZtyjK0leYdsXV5g9jtsIPlP1J tul69SpsZ3//ZCUQFb1JiqUyCw== X-Google-Smtp-Source: ACcGV6343XHzISRvJSV9SnoKgUQylTkbzy9IfOpMCuTSllN2bIYTuO+5HNtF1FlUEruThv0H8bj1Bw== X-Received: by 2002:a63:5d03:: with SMTP id r3-v6mr11016224pgb.445.1538410561460; Mon, 01 Oct 2018 09:16:01 -0700 (PDT) Received: from evgreen2.mtv.corp.google.com ([2620:15c:202:201:e418:c825:76cf:5f64]) by smtp.gmail.com with ESMTPSA id 72-v6sm14629801pfr.115.2018.10.01.09.15.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 Oct 2018 09:16:00 -0700 (PDT) From: Evan Green To: Doug Gilbert , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nick Desaulniers , Christoph Hellwig , Robb Glasser , Evan Green , stable@vger.kernel.org Subject: [PATCH RESEND] scsi: sg: Prevent potential double frees in sg driver Date: Mon, 1 Oct 2018 09:15:06 -0700 Message-Id: <20181001161506.100284-1-evgreen@chromium.org> X-Mailer: git-send-email 2.16.4 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Robb Glasser sg_ioctl could be spammed by requests, leading to a double free in __free_pages. This protects the entry points of sg_ioctl where the memory could be corrupted by a double call to __free_pages if multiple requests are happening concurrently. Signed-off-by: Robb Glasser Signed-off-by: Nick Desaulniers Signed-off-by: Evan Green Cc: stable@vger.kernel.org --- Reposting this patch from last summer, as it looks like it fell in between the cracks. drivers/scsi/sg.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 8a254bb46a9b..25579d8a16b5 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -924,8 +924,10 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg) return -ENXIO; if (!access_ok(VERIFY_WRITE, p, SZ_SG_IO_HDR)) return -EFAULT; + mutex_lock(&sfp->parentdp->open_rel_lock); result = sg_new_write(sfp, filp, p, SZ_SG_IO_HDR, 1, read_only, 1, &srp); + mutex_unlock(&sfp->parentdp->open_rel_lock); if (result < 0) return result; result = wait_event_interruptible(sfp->read_wait,