From patchwork Mon Jul 31 08:40:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Natalenko X-Patchwork-Id: 13334066 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 50DA5C001DE for ; Mon, 31 Jul 2023 08:44:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231185AbjGaIow (ORCPT ); Mon, 31 Jul 2023 04:44:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231193AbjGaIoV (ORCPT ); Mon, 31 Jul 2023 04:44:21 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F46044B5 for ; Mon, 31 Jul 2023 01:40:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690792840; 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=tptzp+ajAKS5fHUGnepcgiEVA2vq/obigXOKUmVfnkc=; b=HobiapIgyV0IVRd5+A27IGBN6wbiZVPnlVxlrvlRgBiAvnIdw29StdfOFT987IAnCR6Tai skWS2tSjw7NPQ39FMxOmDzxtwK3/CoL2L2k5apcWhL1dZW69UgidTGLvLn6aSmd6UtliyQ NhvDfFE2anydr1/GiMdbq7ZxTCQi6BU= 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-160-Mxl4Fo_aN3aEdc8V_46zjg-1; Mon, 31 Jul 2023 04:40:36 -0400 X-MC-Unique: Mxl4Fo_aN3aEdc8V_46zjg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1C2A51C2C5A6; Mon, 31 Jul 2023 08:40:36 +0000 (UTC) Received: from localhost (unknown [10.45.224.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB01A2166B25; Mon, 31 Jul 2023 08:40:35 +0000 (UTC) From: Oleksandr Natalenko To: linux-kernel@vger.kernel.org Cc: linux-scsi@vger.kernel.org, Saurav Kashyap , Johannes Thumshirn , David Laight , GR-QLogic-Storage-Upstream@marvell.com, "James E.J. Bottomley" , "Martin K. Petersen" , Jozef Bacik , Laurence Oberman , Rob Evers Subject: [PATCH v2 0/3] scsi: qedf: sanitise uaccess Date: Mon, 31 Jul 2023 10:40:31 +0200 Message-ID: <20230731084034.37021-1-oleksandr@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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. Changes since v1 [1]: * use scnprintf() for on-stack buffers too * adjust an on-stack buffer size in qedf_dbg_debug_cmd_read() to be a multiple of 8, and also size it properly * accumulate acks and reviews [1] https://lore.kernel.org/lkml/20230728065819.139694-1-oleksandr@redhat.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 Tested-by: Laurence Oberman