Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3422285pxf; Mon, 29 Mar 2021 01:36:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBtdYmeyrg2c9HubSpjKfsotBc8wyML8SDkzvP6K9d0g3fkedDxxkM4DheH+AHTuHBk5Vk X-Received: by 2002:a17:906:f12:: with SMTP id z18mr27548935eji.132.1617007000691; Mon, 29 Mar 2021 01:36:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617007000; cv=none; d=google.com; s=arc-20160816; b=btHyWPcNzo9W5zMaIF5XMStPjaG9uXif+/OjZ39+iNQ4Bz+gfPKZdfT0NQYuoWHmvt f5lhaRA61KF9fUpyRZm6ktCH5PssirwX2DQQxxpk0Fo915CViRdSB/XEB2DgB3IWHdcd bViU1XNyS3lO3D/hdDAvIF5ei2Rs7+SvV4/mwpl/L4ybr0UOwOwJdfdMrsAy1IyUQmTs +v2SBs/kIREZLh4BsuHHxR8FVp7186MRtHfntinrD0PzPuufqxCBvqZ+49U6pbFy7lGz LWLt9JheZt75jO6dgfupeg4M2p8jBmuAFbYO56mqMfNeXYcAC+06YqhHhjNgXWDEgEno kc3A== 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=WNGCSVTpqhbgR4UtWECEVEPajtrr7a3s3ZRtOGuoP7Q=; b=YKQj601fgTJ5XHbUw78kc5EnJClDjp2P4GeU1bzTiPXwAd/6hQNkIh/PG4lwFwnKt6 at7KIaD54lwwyqufl0rNmfNNdU2SHYrBOCVMRlRU/xtJvj8NrKkKl+hH5U9YRAtD88ay 10ciuu/r9tSScR/5ZgmPzdoDhPlWnazioc4Wgm7Rij0WDFmFcxmXokCuxkk5EH6Dkjbn Y+ey+97j9Xmn/qpWSB86QxZHsfjUtXpyWAgl46zvCpkvDdo2ztn5pLjIIErfTxJtD4+L ObQGwaDOXs76FglVFBHu8LBP64ZvlpPRZmFXNllmNbgJIzqf/STRABaVa8a6OIdpHHaI Mveg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=n3ETSvgn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nc38si13904707ejc.362.2021.03.29.01.36.18; Mon, 29 Mar 2021 01:36:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=n3ETSvgn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234276AbhC2Icj (ORCPT + 99 others); Mon, 29 Mar 2021 04:32:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:36632 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232419AbhC2IUZ (ORCPT ); Mon, 29 Mar 2021 04:20:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9036161613; Mon, 29 Mar 2021 08:20:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617006025; bh=LCfOYbdDrWCE+GJPVozw9HGEGOggj0If07yc6i7jxEg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n3ETSvgnWhVtLcMZRh0YJlItRw0WXcb55td8KlAjNOxeZ/dYDJthyP/XKmOB9FGv3 sOKH3ozhe/HRIFoUItuP7xrihzLiHgDqy4kOwCTwAqsVJavk10ersCNY1b2LAkInn4 7Ku9IR5E22mXa/qabOx+BpZlBpivqkb6XNSgQFDo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mikulas Patocka , Dan Carpenter , Mike Snitzer Subject: [PATCH 5.10 090/221] dm ioctl: fix out of bounds array access when no devices Date: Mon, 29 Mar 2021 09:57:01 +0200 Message-Id: <20210329075632.214146695@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210329075629.172032742@linuxfoundation.org> References: <20210329075629.172032742@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mikulas Patocka commit 4edbe1d7bcffcd6269f3b5eb63f710393ff2ec7a upstream. If there are not any dm devices, we need to zero the "dev" argument in the first structure dm_name_list. However, this can cause out of bounds write, because the "needed" variable is zero and len may be less than eight. Fix this bug by reporting DM_BUFFER_FULL_FLAG if the result buffer is too small to hold the "nl->dev" value. Signed-off-by: Mikulas Patocka Reported-by: Dan Carpenter Cc: stable@vger.kernel.org Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/md/dm-ioctl.c +++ b/drivers/md/dm-ioctl.c @@ -529,7 +529,7 @@ static int list_devices(struct file *fil * Grab our output buffer. */ nl = orig_nl = get_result_buffer(param, param_size, &len); - if (len < needed) { + if (len < needed || len < sizeof(nl->dev)) { param->flags |= DM_BUFFER_FULL_FLAG; goto out; }