Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4379543ioa; Wed, 27 Apr 2022 02:28:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMMZe2suDCxt+OeSn1VXQuj60fwCjI2FQTMHCiATEmzdUSmCO1H1+OBCwkjatZX9Q47/3n X-Received: by 2002:a17:90b:33cc:b0:1ce:a3fe:af41 with SMTP id lk12-20020a17090b33cc00b001cea3feaf41mr32026390pjb.229.1651051696663; Wed, 27 Apr 2022 02:28:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651051696; cv=none; d=google.com; s=arc-20160816; b=n0m3uhXkFbQbuPiwqV4vVfbDwMdsyIJQQFZdz5dYNzdteoaHO4bcAQ1jS1xmbCaBo4 okEH+xSoktXEN2cD+WDCX37wnnS8qXxOUNJ+7XmOTOw+s3EwySZZCeMoxFnJ0e/JPG+5 NU21oWjm1KN2+hMPZkszgrtDSw0koGJmiQhF7LwnFSaXvim94qxgbC4AmqIeEkC3434B bpzEBPXJt+eygQSY65T1zDQs/XlKjG3T2bwk0pp0XpCKej1FmeR21hv+a3g+SR66A001 CGwSWrijL3XO9cEUg7tkmRraCjO7B3+/E6lfWNjZZ6HAItl/E9zXkeUlAWK0+yHuwaAX VMmg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=irT2YUYD/YU6zKdHdVcygErIGaR8gdfLDaBOjP3MjrQ=; b=OFt094KFdFtzTcDdIp8T4alaBKHWwhryl2o1/RJh8N4LmMOZvTkH+ZKxhnOj4yvz5P VdB6tNQvHVYB/uky8GBaUNcleT/bkf/BwUR4I0oNoXcUnGWYJD0HEkeW4VH+7DyTzQKh 3cYtkoTI5pI9PxAGwZL/msv9juCc41f4BH4ozr46uXlR/fBCypQUWVdK/q5kJ3HzEgsW e8Ts5rHLUqXzg9rfmWykCrj4/vmA1i/TJIfkcCQCjX/fUErtewILVctoYUc0+T2GDfJM wT2Qy8yyqqjl2BDkZCW46U0BxFIvkfV+eclQlWjwKMOD+fCliw/QgtcU/h6mj5VT2Q8+ w1Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XiXaC0KU; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id e16-20020a17090301d000b00153ce7c9244si1285362plh.97.2022.04.27.02.28.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 02:28:16 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XiXaC0KU; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D3AA81F034F; Wed, 27 Apr 2022 02:10:44 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240776AbiDZJMV (ORCPT + 99 others); Tue, 26 Apr 2022 05:12:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347343AbiDZIvU (ORCPT ); Tue, 26 Apr 2022 04:51:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63D8DD0A80; Tue, 26 Apr 2022 01:40:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B4F776104A; Tue, 26 Apr 2022 08:40:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4291C385B0; Tue, 26 Apr 2022 08:40:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650962411; bh=QWLitrRvFmVyVyJOX1rFDP8ZYjWDXNK6XBXYNABfqg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XiXaC0KUNB1O3jxleJlZFZKueqJY3c2oleBs2Is6VvJypdYjeaP+zESH/P0TBg2Pd 3FwbepJyzbiLw3gabea7bT1PZjEKKJiT5o+ypJDYpFnKQEF82UE8pxvCGjWIL0ZCcP Btya+hW8kHPuMKkhD4g9mUtPugBvVg2B5kCyeGVY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , Tom Rix , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.15 088/124] scsi: sr: Do not leak information in ioctl Date: Tue, 26 Apr 2022 10:21:29 +0200 Message-Id: <20220426081749.801857443@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220426081747.286685339@linuxfoundation.org> References: <20220426081747.286685339@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE 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 From: Tom Rix [ Upstream commit faad6cebded8e0fd902b672f220449b93db479eb ] sr_ioctl.c uses this pattern: result = sr_do_ioctl(cd, &cgc); to-user = buffer[]; kfree(buffer); return result; Use of a buffer without checking leaks information. Check result and jump over the use of buffer if there is an error. result = sr_do_ioctl(cd, &cgc); if (result) goto err; to-user = buffer[]; err: kfree(buffer); return result; Additionally, initialize the buffer to zero. This problem can be seen in the 2.4.0 kernel. Link: https://lore.kernel.org/r/20220411174756.2418435-1-trix@redhat.com Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reviewed-by: Christoph Hellwig Signed-off-by: Tom Rix Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/sr_ioctl.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/sr_ioctl.c b/drivers/scsi/sr_ioctl.c index ddd00efc4882..fbdb5124d7f7 100644 --- a/drivers/scsi/sr_ioctl.c +++ b/drivers/scsi/sr_ioctl.c @@ -41,7 +41,7 @@ static int sr_read_tochdr(struct cdrom_device_info *cdi, int result; unsigned char *buffer; - buffer = kmalloc(32, GFP_KERNEL); + buffer = kzalloc(32, GFP_KERNEL); if (!buffer) return -ENOMEM; @@ -55,10 +55,13 @@ static int sr_read_tochdr(struct cdrom_device_info *cdi, cgc.data_direction = DMA_FROM_DEVICE; result = sr_do_ioctl(cd, &cgc); + if (result) + goto err; tochdr->cdth_trk0 = buffer[2]; tochdr->cdth_trk1 = buffer[3]; +err: kfree(buffer); return result; } @@ -71,7 +74,7 @@ static int sr_read_tocentry(struct cdrom_device_info *cdi, int result; unsigned char *buffer; - buffer = kmalloc(32, GFP_KERNEL); + buffer = kzalloc(32, GFP_KERNEL); if (!buffer) return -ENOMEM; @@ -86,6 +89,8 @@ static int sr_read_tocentry(struct cdrom_device_info *cdi, cgc.data_direction = DMA_FROM_DEVICE; result = sr_do_ioctl(cd, &cgc); + if (result) + goto err; tocentry->cdte_ctrl = buffer[5] & 0xf; tocentry->cdte_adr = buffer[5] >> 4; @@ -98,6 +103,7 @@ static int sr_read_tocentry(struct cdrom_device_info *cdi, tocentry->cdte_addr.lba = (((((buffer[8] << 8) + buffer[9]) << 8) + buffer[10]) << 8) + buffer[11]; +err: kfree(buffer); return result; } @@ -384,7 +390,7 @@ int sr_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn) { Scsi_CD *cd = cdi->handle; struct packet_command cgc; - char *buffer = kmalloc(32, GFP_KERNEL); + char *buffer = kzalloc(32, GFP_KERNEL); int result; if (!buffer) @@ -400,10 +406,13 @@ int sr_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn) cgc.data_direction = DMA_FROM_DEVICE; cgc.timeout = IOCTL_TIMEOUT; result = sr_do_ioctl(cd, &cgc); + if (result) + goto err; memcpy(mcn->medium_catalog_number, buffer + 9, 13); mcn->medium_catalog_number[13] = 0; +err: kfree(buffer); return result; } -- 2.35.1