From patchwork Fri Jul 28 06:58:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Natalenko X-Patchwork-Id: 707899 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56E62C41513 for ; Fri, 28 Jul 2023 06:59:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233470AbjG1G7M (ORCPT ); Fri, 28 Jul 2023 02:59:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233361AbjG1G7K (ORCPT ); Fri, 28 Jul 2023 02:59:10 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DE4619AF for ; Thu, 27 Jul 2023 23:58:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690527504; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=BD044lTlj7rwbRv6ZfiORHHK6QURk2L1R485ZfvK5Io=; b=Xb1+pkESj/YeUaRfT/ZWurTSgAIHUKVTv5TLG5MW1MPPF/Klbm5rW3NNnYhs3e+JbfoCKk 1Oc71URxYBwMI9bvA0YGuZ+qh+IzvFfqg5DFnU9+81vb1qwaiMOiVziKZocHa+2zPNYJFg aWeI+AMwK17WIlSvlzbM81ppCbp9JPE= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-211-wzRbNYeNOHWfKbi6qkDEMA-1; Fri, 28 Jul 2023 02:58:20 -0400 X-MC-Unique: wzRbNYeNOHWfKbi6qkDEMA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 27F963C025CE; Fri, 28 Jul 2023 06:58:20 +0000 (UTC) Received: from localhost (unknown [10.45.224.187]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCDACF7830; Fri, 28 Jul 2023 06:58:19 +0000 (UTC) From: Oleksandr Natalenko To: linux-kernel@vger.kernel.org Cc: linux-scsi@vger.kernel.org, Saurav Kashyap , Johannes Thumshirn , GR-QLogic-Storage-Upstream@marvell.com, "James E.J. Bottomley" , "Martin K. Petersen" , Jozef Bacik , Laurence Oberman , Rob Evers Subject: [PATCH 0/3] scsi: qedf: sanitise uaccess Date: Fri, 28 Jul 2023 08:58:16 +0200 Message-ID: <20230728065819.139694-1-oleksandr@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org qedf driver, debugfs part of it specifically, touches __user pointers directly for printing out info to userspace via sprintf(), which may cause crash like this: BUG: unable to handle kernel paging request at 00007ffd1d6b43a0 IP: [] string.isra.7+0x6a/0xf0 Oops: 0003 [#1] SMP Call Trace: [] vsnprintf+0x201/0x6a0 [] sprintf+0x56/0x80 [] qedf_dbg_stop_io_on_error_cmd_read+0x6d/0x90 [qedf] [] vfs_read+0x9f/0x170 [] SyS_pread64+0x92/0xc0 Avoid this by preparing the info in a kernel buffer first, either allocated on stack for small printouts, or via vmalloc() for big ones, and then copying it to the userspace properly. Previous submission is an RFC: [1]. There are no code changes since then. The RFC prefix is dropped. The Tested-by tag from Laurence is added. There's similar submission from Saurav [2], but we agreed I could nack it and proceed with my one. [1] https://lore.kernel.org/linux-scsi/20230724120241.40495-1-oleksandr@redhat.com/ [2] https://lore.kernel.org/linux-scsi/20230726101236.11922-1-skashyap@marvell.com/ Oleksandr Natalenko (3): scsi: qedf: do not touch __user pointer in qedf_dbg_stop_io_on_error_cmd_read() directly scsi: qedf: do not touch __user pointer in qedf_dbg_debug_cmd_read() directly scsi: qedf: do not touch __user pointer in qedf_dbg_fp_int_cmd_read() directly drivers/scsi/qedf/qedf_dbg.h | 2 ++ drivers/scsi/qedf/qedf_debugfs.c | 35 +++++++++++++++++++------------- 2 files changed, 23 insertions(+), 14 deletions(-) Reviewed-by: Laurence Oberman Reviewed-by: Johannes Thumshirn