Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp574424lqr; Wed, 5 Jun 2024 14:38:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWqwgT5PmAhBwJ7WRLvftGbIgljVfoMD58GbcWM0Gt2EemzNaROQI1/i87BtHbmLSl/YtvUKnVuSxkIaxnS5MWz44PBbZ1koxSPyR4tHA== X-Google-Smtp-Source: AGHT+IG1mvdVQCIM5y6ku8r1Yq1/b9I8GPQK83CKj3cYh1PbKgQ3xFuKZSHiI/RPXcQW2W6JPJPy X-Received: by 2002:a05:600c:4f49:b0:421:36da:9438 with SMTP id 5b1f17b1804b1-4215633a175mr40101855e9.28.1717623484220; Wed, 05 Jun 2024 14:38:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717623484; cv=pass; d=google.com; s=arc-20160816; b=Jjrz+FDhIs1WYxlug6s3aXT17N3TH1QAsbkn5+hMQsKs6sPt+0rJP/RWjLUGVMzMhL oV8zXgtGmJ65ehzCGfz3LR4zXu4bNnSiGpPNe12zLAo9I3pl0KBQaJlm4cp2Ufb2PGyN /WdgXXo35rC0zvjKY7Dljt/nQKL4Ob1N3MmhCDV4yWdAqLksRUyFcedof3RqUphvxhwD QTzNcw0vQx4IL9FjV759+LxnSSiznXGZ8Ul3An/PTOnlqV5GAuDis4/uEsrnWBxPQrZk vbgsRDaebWzniDoKUi2XeUei5MC1p7yVHUIea21Nw4IuGth5oLkleWZGrFjsEUPXhaVj ee1Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=JvVC7BaTilq9Ww7g4mw3O5T4PPv3xf2DesSD7h+cHxQ=; fh=SnRW/TdnGZ1r3++B+VIJ4NkUXb3kVoWM6xpux/to0mc=; b=wqqmrKI/OHyHzy8zz2HkYdC5k3/ZQE8j+enGHNp9AMcguN2z1ZEYlVHF9FU/qdz2P4 XPhlJP3lu57tD0oK/YI5JXD+ZBigofWWJ4sCu85C0opEtQYYDrOFAKXykTZFwgvJWlXG pK5bS+jXTlbdSvRGjIikxcfvw7Et83ZYcr6/huOB6IJsfICiEmuLTkmUqlHIWYMMK6fj wIIKDFPp3Vw+B1fQluF8NxO/7rnJGSkdZleqRahzhGE/QKFOs0uv3hLDb8f6NZ1hE+31 kFWkx3P287TuQ3Gm1kcbK65AJnQ934jfFB7ymFSsusYAn3BvYUQNTs1SWQ++o+MZ3TkN yK0g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=eEGbfY6F; arc=pass (i=1 spf=pass spfdomain=yandex.ru dkim=pass dkdomain=yandex.ru dmarc=pass fromdomain=yandex.ru); spf=pass (google.com: domain of linux-kernel+bounces-203306-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203306-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a68ea259415si406529266b.362.2024.06.05.14.38.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:38:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-203306-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=eEGbfY6F; arc=pass (i=1 spf=pass spfdomain=yandex.ru dkim=pass dkdomain=yandex.ru dmarc=pass fromdomain=yandex.ru); spf=pass (google.com: domain of linux-kernel+bounces-203306-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203306-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A70141F232DF for ; Wed, 5 Jun 2024 21:38:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0007415FA73; Wed, 5 Jun 2024 21:37:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="eEGbfY6F" Received: from forward204b.mail.yandex.net (forward204b.mail.yandex.net [178.154.239.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36CCF15F3FF; Wed, 5 Jun 2024 21:37:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.153 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717623441; cv=none; b=ZBGaXM0907G1wkSt6gaeoHpmvW4bdEHRngrTEsObmGlkvmCtdV3leSEoeuzAe/dtMsqVUmp2qU8l/RGPueKF2xS2EvxeUDHRWGGxSa7J4TN3YbWwVRgQTXk/cRkjNRUY4Ti7C7ZHd0SZz246yWkRtgEPezvY/mineK+0ahUi774= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717623441; c=relaxed/simple; bh=I1MC/J9J5wZTsyCTVV7/Js6exyl5QJIVotMGCkz7gHE=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=gCysgjTVeTLTHcxCvECj/7+XNDkwmVdsc5Hjh9iZPlJfn0rZ12RsIPDZGvXzwYInCObAxnM0yYbUmHlmvW/fs2gY4UFoPLqhRnMeKXXnEuJYFtTFh8iI3J8y5Q5jDq5dJcR2RfEBL8mJtVoGx4oKJHVl1fwYPtcqwYyMSiOg120= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru; spf=pass smtp.mailfrom=yandex.ru; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b=eEGbfY6F; arc=none smtp.client-ip=178.154.239.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yandex.ru Received: from forward103c.mail.yandex.net (forward103c.mail.yandex.net [IPv6:2a02:6b8:c03:500:1:45:d181:d103]) by forward204b.mail.yandex.net (Yandex) with ESMTPS id A7FF36677C; Thu, 6 Jun 2024 00:34:42 +0300 (MSK) Received: from mail-nwsmtp-smtp-production-main-90.myt.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-90.myt.yp-c.yandex.net [IPv6:2a02:6b8:c12:4486:0:640:b366:0]) by forward103c.mail.yandex.net (Yandex) with ESMTPS id 56F26608E1; Thu, 6 Jun 2024 00:34:34 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-90.myt.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id VYgH11SMo8c0-8YgXmBOX; Thu, 06 Jun 2024 00:34:33 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1717623273; bh=JvVC7BaTilq9Ww7g4mw3O5T4PPv3xf2DesSD7h+cHxQ=; h=Message-Id:Date:Cc:Subject:To:From; b=eEGbfY6FDHA/a4AYVa9egz65CoedLqMAD0KicAFtGcohEDS7vLrVtcIBYSa1d/o64 KYw/NwsCGJzEocE9uqbi4vYJRCUoFJYqt6F7edcUSidRwinI52zL3WLD3gh3BOtjL3 +tEI8vrLVZ81XoHSrRIfr4Gh262osk7RrVhiZ71s= Authentication-Results: mail-nwsmtp-smtp-production-main-90.myt.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Mikhail Ukhin To: Greg Kroah-Hartman , Jens Axboe Cc: Mikhail Ukhin , stable@vger.kernel.org, linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, Pavel Koshutin , lvc-project@linuxtesting.org, Artem Sadovnikov , Mikhail Ivanov Subject: [PATCH v3 5.10/5.15] ata: libata-scsi: check cdb length for VARIABLE_LENGTH_CMD commands Date: Thu, 6 Jun 2024 00:34:28 +0300 Message-Id: <20240605213428.4040-1-mish.uxin2012@yandex.ru> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit No upstream commit exists for this patch. Fuzzing of 5.10 stable branch reports a slab-out-of-bounds error in ata_scsi_pass_thru. The error is fixed in 5.18 by commit ce70fd9a551a ("scsi: core: Remove the cmd field from struct scsi_request") upstream. Backporting this commit would require significant changes to the code so it is bettter to use a simple fix for that particular error. The problem is that the length of the received SCSI command is not validated if scsi_op == VARIABLE_LENGTH_CMD. It can lead to out-of-bounds reading if the user sends a request with SCSI command of length less than 32. Found by Linux Verification Center (linuxtesting.org) with Syzkaller. Signed-off-by: Artem Sadovnikov Signed-off-by: Mikhail Ivanov Signed-off-by: Mikhail Ukhin --- v2: The new addresses were added and the text was updated. v3: Checking has been moved to the function ata_scsi_var_len_cdb_xlat at the request of Damien Le Moal drivers/ata/libata-scsi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index dfa090ccd21c..38488bd813d1 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -3948,7 +3948,11 @@ static unsigned int ata_scsi_var_len_cdb_xlat(struct ata_queued_cmd *qc) struct scsi_cmnd *scmd = qc->scsicmd; const u8 *cdb = scmd->cmnd; const u16 sa = get_unaligned_be16(&cdb[8]); + u8 scsi_op = scmd->cmnd[0]; + if (scsi_op == VARIABLE_LENGTH_CMD && scmd->cmd_len < 32) + return 1; + /* * if service action represents a ata pass-thru(32) command, * then pass it to ata_scsi_pass_thru handler. -- 2.25.1