From patchwork Thu Aug 3 19:02:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 9879735 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C2AAA60360 for ; Thu, 3 Aug 2017 19:03:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA55C2895F for ; Thu, 3 Aug 2017 19:03:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF29828961; Thu, 3 Aug 2017 19:03:25 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 6877B2895F for ; Thu, 3 Aug 2017 19:03:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751918AbdHCTDN (ORCPT ); Thu, 3 Aug 2017 15:03:13 -0400 Received: from mail-pf0-f175.google.com ([209.85.192.175]:33370 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751743AbdHCTDM (ORCPT ); Thu, 3 Aug 2017 15:03:12 -0400 Received: by mail-pf0-f175.google.com with SMTP id d67so9826292pfc.0 for ; Thu, 03 Aug 2017 12:03:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=nv538L9KOp17tVHcqe6IQBwetNIinwmoxrQrKxPucsw=; b=g7viLeo+dHBBWY5NKoO1fcsIAlwxKVeYx999MxaW6AS6DniQv0allaiKftC8GsqrjX 2ytWmsxQmn2O8rfFFMUpfQVDKAPILu+qg62va/9tZ/msHudukKUXtZsP9qqSEbyeGifg BZkiSBRRxHl9nu1FH1sl7iJICQoxfRBkSSx1gNlb74T5NYUa95t4ugBpvnIRAbTMcNHB l/qTWhZQWVNW/a3BCVKiCIjPGpf+nN6JDCxNSioEaa7NV/o9xLlhYb9DeFrA0jEzEA03 EQC7n/cwiIRPgwqX0sX6obJGIUbWH6Zw4fcFRsS1X3gOiqhYE1b+rSoBRT/a/DVmBVOi gkIw== 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=nv538L9KOp17tVHcqe6IQBwetNIinwmoxrQrKxPucsw=; b=gHSH9SnpQj6774CyjW03OMOOuuJ2ItNP3/6eSavekUO4pirM8N9269tFtZNsj2uX4i TBrpfpt7Kled/x+hvpuh3QofcrAqpXmVzIa8152026ZYz0WyHFu2QzTZHJ01UkCkKlkk QDeQ7ILqKe/dj3EcmZJ04zpkJ6p67V6stgeCb3iJf/5FY/KEC5elSToUuuY2I9j5L/eH F8QCxiJOtqtP8LyRIN/iKiPPVxL/OSDL1larYBCo6aDk8bgFfCht1vLInedQxdqjGGFX iM4DkhkPCCJDQibvRhGdPzBFCBVcdVrcQroIfrHmQgWl/+8Keev56wOupKXL1mmRNSMb /p6w== X-Gm-Message-State: AIVw111jnact4FbxgWJVdurNQiomwcIS5WnOpflbhKcCTlWGgmf+Zmtc EwLmL1yiDtvn03/x X-Received: by 10.84.232.143 with SMTP id i15mr3019519plk.248.1501786991681; Thu, 03 Aug 2017 12:03:11 -0700 (PDT) Received: from ndesaulniers0.mtv.corp.google.com ([100.98.120.50]) by smtp.gmail.com with ESMTPSA id q76sm17271339pfg.42.2017.08.03.12.03.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 Aug 2017 12:03:11 -0700 (PDT) From: Nick Desaulniers Cc: hare@suse.de, jthumshirn@suse.de, hch@lst.de, salyzyn@google.com, gregkh@linuxfoundation.org, Robb Glasser , Nick Desaulniers , Doug Gilbert , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] scsi: sg: Prevent potential double frees in sg driver Date: Thu, 3 Aug 2017 12:02:47 -0700 Message-Id: <20170803190248.51537-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.14.0.rc1.383.gd1ce394fe2-goog To: unlisted-recipients:; (no To-header on input) 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 --- drivers/scsi/sg.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 4fe606b000b4..40fe71f4c863 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -883,8 +883,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,