From patchwork Wed Sep 20 20:45:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9962583 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 9435C60208 for ; Wed, 20 Sep 2017 20:59:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8742225D9E for ; Wed, 20 Sep 2017 20:59:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BC6029204; Wed, 20 Sep 2017 20:59:14 +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=-4.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, URIBL_BLACK 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 1233125D9E for ; Wed, 20 Sep 2017 20:59:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752141AbdITU7I (ORCPT ); Wed, 20 Sep 2017 16:59:08 -0400 Received: from mail-pg0-f41.google.com ([74.125.83.41]:51607 "EHLO mail-pg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752095AbdITUwy (ORCPT ); Wed, 20 Sep 2017 16:52:54 -0400 Received: by mail-pg0-f41.google.com with SMTP id k193so2335564pgc.8 for ; Wed, 20 Sep 2017 13:52:54 -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:in-reply-to:references; bh=pyFDIaXBXd/xydwRlXh6RPXOHouRALUO1bJrvgXof6w=; b=Yxm5lYvFf3wPzsa4PgX87jT8KcfJT1KNmq6mG51YRzB3AMGSxCKi+4cqK2iFsqUN2K 1w9sLkgzP6dnkqx4sGDuEoZgKSaeWEJnvkbNIX3UwAR57d86hwWh1mWTlagukyj4w3Ja AikwSJlYm1sjLoTgNAMONtYGPAXtkRkETUPb0= 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:in-reply-to :references; bh=pyFDIaXBXd/xydwRlXh6RPXOHouRALUO1bJrvgXof6w=; b=ksfttoU/9sti9ZFK+sNTTvatxRnf4fiLbG0uuovtbarDGynAUJC185R+vGBR+uug8Q ODQpHlbwRLfIWK2TK79ndpIxhIQjuFl8DsdlLOm4AtYtv7gsN4+o1vOj051U07XLSFlv 8tLicSCGDlYVlJp1lLMENoxQ3HHoRVB0oGwI7/rVcqABVMDpXLdB7yyViLWaUWun7XBi IA2H8jrfvTWfMRtRUHsPGUB34cKDlb+G9q85QFSbOL4pX4OcmuYpJ4uz3cdnvG4nU6EN d2bBo5JISvalRL/5XK52etPM5vjHXQ9eRJEhqttUtSIjeIciN6A7A3JNrw22cohYSyw+ CxoA== X-Gm-Message-State: AHPjjUie08H/HmOu0kLsgmT4uP+Mpilz0ybNMsvUY3hSwRGlEh3DEtoi 50y2dz+YxEf7+vJ1EomT9ZDcHw== X-Google-Smtp-Source: AOwi7QBeSrwPzi/1uoSQ8zSMwjWWj98tbYXJI5cT0XsDEVKGZlEkHLXEUEV1RA2HfZs3ZePpS2D8hA== X-Received: by 10.84.133.111 with SMTP id 102mr1087393plf.204.1505940773930; Wed, 20 Sep 2017 13:52:53 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id x28sm9795273pfi.8.2017.09.20.13.52.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Sep 2017 13:52:52 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , David Windsor , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, netdev@vger.kernel.org, linux-mm@kvack.org, kernel-hardening@lists.openwall.com Subject: [PATCH v3 17/31] scsi: Define usercopy region in scsi_sense_cache slab cache Date: Wed, 20 Sep 2017 13:45:23 -0700 Message-Id: <1505940337-79069-18-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505940337-79069-1-git-send-email-keescook@chromium.org> References: <1505940337-79069-1-git-send-email-keescook@chromium.org> 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: David Windsor SCSI sense buffers, stored in struct scsi_cmnd.sense and therefore contained in the scsi_sense_cache slab cache, need to be copied to/from userspace. cache object allocation: drivers/scsi/scsi_lib.c: scsi_select_sense_cache(...): return ... ? scsi_sense_isadma_cache : scsi_sense_cache scsi_alloc_sense_buffer(...): return kmem_cache_alloc_node(scsi_select_sense_cache(), ...); scsi_init_request(...): ... cmd->sense_buffer = scsi_alloc_sense_buffer(...); ... cmd->req.sense = cmd->sense_buffer example usage trace: block/scsi_ioctl.c: (inline from sg_io) blk_complete_sghdr_rq(...): struct scsi_request *req = scsi_req(rq); ... copy_to_user(..., req->sense, len) scsi_cmd_ioctl(...): sg_io(...); In support of usercopy hardening, this patch defines a region in the scsi_sense_cache slab cache in which userspace copy operations are allowed. This region is known as the slab cache's usercopy region. Slab caches can now check that each copy operation involving cache-managed memory falls entirely within the slab's usercopy region. Signed-off-by: David Windsor [kees: adjust commit log, provide usage trace] Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org Signed-off-by: Kees Cook --- drivers/scsi/scsi_lib.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 9cf6a80fe297..88bfab251693 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -79,14 +79,15 @@ int scsi_init_sense_cache(struct Scsi_Host *shost) if (shost->unchecked_isa_dma) { scsi_sense_isadma_cache = kmem_cache_create("scsi_sense_cache(DMA)", - SCSI_SENSE_BUFFERSIZE, 0, - SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA, NULL); + SCSI_SENSE_BUFFERSIZE, 0, + SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA, NULL); if (!scsi_sense_isadma_cache) ret = -ENOMEM; } else { scsi_sense_cache = - kmem_cache_create("scsi_sense_cache", - SCSI_SENSE_BUFFERSIZE, 0, SLAB_HWCACHE_ALIGN, NULL); + kmem_cache_create_usercopy("scsi_sense_cache", + SCSI_SENSE_BUFFERSIZE, 0, SLAB_HWCACHE_ALIGN, + 0, SCSI_SENSE_BUFFERSIZE, NULL); if (!scsi_sense_cache) ret = -ENOMEM; }