Received: by 2002:ab2:7407:0:b0:1f4:b336:87c4 with SMTP id e7csp131989lqn; Thu, 11 Apr 2024 16:59:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWMZ0V8pUMfehmny/GpxyyLJ39AFmo7wynL01MtA19ComaNufYbeZhBKiNJ3mFTALlIR50jo+ZBOWBbZKXfkj7Zbze2CL6CIuJ6GDTwxQ== X-Google-Smtp-Source: AGHT+IHiMvW85INasboX4wWciS5Ji4v0KjiDiwCJwoyOMyguZYERq7nVbp/TADYRzJQNBTSZl1dI X-Received: by 2002:a05:6a20:1595:b0:1a7:5887:c96d with SMTP id h21-20020a056a20159500b001a75887c96dmr1683348pzj.57.1712879993766; Thu, 11 Apr 2024 16:59:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712879993; cv=pass; d=google.com; s=arc-20160816; b=WLbeu1TzWesdky7wsztYyS5o6qere50vXpw0SVcV5yeioziil5OxF8vfzit8hLuYko Dp+6PUXRFXUbatSfmb8vopAUwy8kVYE5ro3HVe7hkYwj9zlo958aFbdHHzCe73qg6NBd V03Jbfe2med9jHSkZ6BibCwktb4uXWqzEA0hsJ3qCoKQhbsIXhVf9wyZbU0Z2eWkfNpN J08kR7Inox1+KwVwA2bsSpY6fXwpOYx6za3yuVnp3wTaFxp2jwIXqSkZ+cYA5V8Q0Hvg tWeKE1Nm4xIhCNLGRpGH5hnS5HhghnvSZiTXl5bondHUZdma37TM/qAhhCs6eDvcXNIH bCyg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:organization:content-language :from:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=94yTnL5iJzi/fNsViRx0iG+E3Lp6Tapw0GLRYhw/UCk=; fh=kV3nQv157Gah5cHVjkowMYUBgUpgoNHj/I+aOdmLimU=; b=ili3p2hAyv0QVBhnN/jJiOIBWV+pSo6dJ1DVhIVLAPakJLHeLk31GlaHK04S60Zlbi ci0gE9xDqHqR4xoMKKYOoIq7CF5EJxS68SFBDJpr0AWQVloZxmNrQ2t2sVw74xNFDeYN 7T5LaMOf1lMh23L4/sBz4l+l+otJbrzsi8hEgm1aqoJ2h9o7VaFgyxOD4AqTKth0f5O+ 8kgztdHKlyq+is7IWwML0nLPhbsLDlbOUABL1aVcP7H78jnTO6A8L90fGbgLoH3+lJcT R5SskFwUCloJBAeSFQDHkd9WBhAw1+Px0o7kHqzxQ4hGqQis1TJ8hqN0y0Os9jRNFROH 0DtA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TmungXsz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-141734-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141734-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id gt13-20020a056a004e0d00b006eabed49580si2186390pfb.305.2024.04.11.16.59.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 16:59:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141734-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TmungXsz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-141734-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141734-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id ED569B216D8 for ; Thu, 11 Apr 2024 23:58:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4ECFC4C629; Thu, 11 Apr 2024 23:58:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TmungXsz" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 63E6347A5D; Thu, 11 Apr 2024 23:58:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712879926; cv=none; b=jzS+ceuTc8g6XVolEbSj583kmMEtWSsOLyv7ggGQkPNyRLTTKiG+YURC0oQFs6hlFZXAE2WIKy0NMSvDrVYEas/3tgoX5OaWQsSpCesDRz+DJ8IH82HvdudX6UUPunu/sNQJVqr1WmmPkKQoVrMkIbI/AW7bxi3eSaP/33wkbsQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712879926; c=relaxed/simple; bh=Rvrx5bIocVoHhqzlQ8FUwZ0hV15oMlthb4VvYCnIU/Q=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=p1fiTk9N4+WtILP+l6qtY5dVfF07shnIxJJM9woAFRWUIF+6iXR5qg+leliuSxrkX0EId2SKVlIUN5cXA05bsHXxP7S1s1BMKuYLue6016ZNQ9XkBB23cBmF1amai5MmtK0tw8iUysVDkiylAKUFLYK/UKAIlPooH2SuCkTHNBU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TmungXsz; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7166CC072AA; Thu, 11 Apr 2024 23:58:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712879926; bh=Rvrx5bIocVoHhqzlQ8FUwZ0hV15oMlthb4VvYCnIU/Q=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=TmungXszWLiOZYvkGczuGKN3KtOLrN2pGFzQyi8Puk4Ctie2iAzXuJkRLXMaNCVjl /kzYCjkvIeCLQrL3HxwxMRlfO8nPqijfxt0LiwRoQ/ykurW1NfTIOInCiwwdQDi0Vg euZwhbSNvrSG3w9jdeBEQZmrOXwqa8EZAUKJNMUqJVYg2YY36lAGfyexFg7VPFeRF5 bw1Uwi/8OzY09cc/jSldM7byXOrs1IxXPPnIuXidNk9Izf9juIN3uKbVTdCVFEJ3kV wDKyTCzztW/vEVN9an3Riee94rg53JKY4GW0JjwjDtgApT/kebR8MpUMDWC9j7KZZk QtbMexSUEo5Bw== Message-ID: Date: Fri, 12 Apr 2024 08:58:42 +0900 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 5.10/5.15] ata: libata-scsi: check cdb length for VARIABLE_LENGTH_CMD commands To: Mikhail Ukhin , Greg Kroah-Hartman , Jens Axboe Cc: stable@vger.kernel.org, linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, Pavel Koshutin , lvc-project@linuxtesting.org, Artem Sadovnikov , Mikhail Ivanov References: <20240411103013.5547-1-mish.uxin2012@yandex.ru> From: Damien Le Moal Content-Language: en-US Organization: Western Digital Research In-Reply-To: <20240411103013.5547-1-mish.uxin2012@yandex.ru> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 4/11/24 19:30, Mikhail Ukhin wrote: > 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. > drivers/ata/libata-scsi.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c > index dfa090ccd21c..77589e911d3d 100644 > --- a/drivers/ata/libata-scsi.c > +++ b/drivers/ata/libata-scsi.c > @@ -4065,6 +4065,9 @@ int __ata_scsi_queuecmd(struct scsi_cmnd *scmd, struct ata_device *dev) > > if (unlikely(!scmd->cmd_len)) > goto bad_cdb_len; > + > + if (scsi_op == VARIABLE_LENGTH_CMD && scmd->cmd_len < 32) > + goto bad_cdb_len; This check should really be in ata_scsi_var_len_cdb_xlat(). Please move it to that function. > > if (dev->class == ATA_DEV_ATA || dev->class == ATA_DEV_ZAC) { > if (unlikely(scmd->cmd_len > dev->cdb_len)) -- Damien Le Moal Western Digital Research