Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp4149607rwb; Mon, 31 Jul 2023 02:06:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlFUHxO34/GTjkpmVJc9GFq6uKLf1yJJWsBHHxdPWFnKaIdcY6tcP7AmS89RMVTMzoZHhRhK X-Received: by 2002:a17:902:ce8d:b0:1b6:6a14:3734 with SMTP id f13-20020a170902ce8d00b001b66a143734mr12467846plg.29.1690794407452; Mon, 31 Jul 2023 02:06:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690794407; cv=none; d=google.com; s=arc-20160816; b=gj29bT97jHBWz/zJpQN7zcPeFvRq3qOIGoPl5YQWVWP9ULsKKKBvJfrHPj7m9GOFfx UXxOe9ypflZifWy65qmSDT/niMp7wUEfpElRnyd+MF71Cmq4ASZZ7xYoznHoywy4APgY hqpukcNntKDgP86EF49hCvr7vjqnAvn3EgNEfbb64YbX0CLOzi0HHfhTRBovRN2zQgjw hGO2NbxxoEhQFv5EknqGmyMMwyi+jqTKnWRGe32PFRkMyq5iF15qtTwhTtSMFeTwXeCH m/2vfdekNYzTMP0xZX0JZTtiKVJ58AqeRLK2s47biPtWysCT8Ij0XrXp52adZ3+P6a3I Ajtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=tptzp+ajAKS5fHUGnepcgiEVA2vq/obigXOKUmVfnkc=; fh=isMFuSHyz90mLfuw9M/ykjSVJvwUg2TnjrAlacjQM+I=; b=toSfMyoq6pniUd0+ZiUz+jD1bwQvFwK8RhQvv1+6b2uqzDfXy+wWgeHPC7kNDdCKz2 huVbfkAApK8Z8IzcYeXpmfT0sbERzNaIS1IggPTnmjS3QCJSzha136K3cdLLr008X4+X IpqVbRSX37ikEabwFVJ6YZ27WVM4+Wbth9GXVyqG9B/2uqITogss1CoBV5aIwDzBpboT HgUiVSj3EoA9JYaVQKa2hVC50Jl79JavR4PHSMb4ufbAjOArxH8suHuB6ix7qEyzerdx MjoygvHqgIOHZvydoeJhd+PN6lFOfTDfTWZxair6qZ+F5D1SGkHNJ0UEjIfOVRUbbHt0 FNYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HobiapIg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lb16-20020a170902fa5000b001b58767a0f7si6812956plb.60.2023.07.31.02.06.35; Mon, 31 Jul 2023 02:06:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HobiapIg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231282AbjGaIox (ORCPT + 99 others); Mon, 31 Jul 2023 04:44:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231236AbjGaIoV (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 9156D44B9 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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-) -- 2.41.0