Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp637825pxj; Thu, 20 May 2021 18:38:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9x26KECctA9zdjHlaM0+TlyX3uKg4sT8FYj9gHsGD7AiUaEKRPSzOdiV5RPACaqFceSUH X-Received: by 2002:a05:6602:164c:: with SMTP id y12mr8702886iow.78.1621561086385; Thu, 20 May 2021 18:38:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621561086; cv=none; d=google.com; s=arc-20160816; b=lnWO9nhq+LLRkw2AIxKkqpkfwqb1b46dvJRQw8Z46mrbJa4g785nScdgVaWfpJVk+Z EUiE4IDGaRjnoOogrEHypQT7BfueTCFuQgFoCUe1ngyHv2E+8RBbnVqO8K4Fdts3A2P7 BlYayAHv1C+bPcjaNAV7uE9SvOd00c+iyPrtmFXXV7fAhel4ck03skfUmOenq7oHpGyb 7DjjnJcAVYSsYvEd5iZJ5ysIfdGGDuM7XFH4PRulNk8o986ggOJwDTAuM8U4JWLmjWZo gjUj9tTLX6CJYP2fAfDqowmuDnHJpThZ+hJAba0gCLuH/JBJhGi3yWdahk71cMIDiA/Z B27w== 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=F0r2ZPp6hHhJ/pFxO5YS1SNHka+UVtTbyejNC5u7nWs=; b=o1z72gL6Vr21u8nxyqH724HqlNZmApwMHNWxvf4Gmydi8FKdjBNV2EgLEOJd7NJT35 Qq77AS1NT4qoRJYUNzq43qGRdYdvyLNMDR/FAl71mN3Qeb02nr9oZ7FlgBr/bvnQBJcF jR2nonfzRLe+MUhLacC/qyiHTZ90WD2J0pe5PwyfAiGAiYQnHo0cC0XQoxppac9FqcgB tpDWovf+rEX+50KZ9wFDIxj4FsJX608Hw7+RRRmK9k7BPCiwVedC1pElnig0CGZ50/DS 1vma78CyIz6hhI0I4JOhBo6EmEIhpJ2y8PO1e+q5MG44+xMpvtDuMfRA++SVy4zPUc1o DrUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WPkNYby0; 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 l11si4009838jak.61.2021.05.20.18.37.53; Thu, 20 May 2021 18:38:06 -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=WPkNYby0; 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 S242695AbhETLnv (ORCPT + 99 others); Thu, 20 May 2021 07:43:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:44180 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241216AbhETLXZ (ORCPT ); Thu, 20 May 2021 07:23:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BD74B61D93; Thu, 20 May 2021 10:12:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505527; bh=Sz6EOdc7yV52bDWQgKlyk4LCblp+4sumZFTP9xmgSn8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WPkNYby0RVXZ0wF7o8zRXbxXwhnvftJ7ieCIVHdouibYWx1KeDJpsiN4ooKjGIXKJ TLwdLGMW7ZuyP7KeXKXGkOPjoJRg43DQ2YEHouAnQJYsSuAFZjbib5nSMln5+C/V3U doSVaqX/gTIQSA5wLEPZCkGAKf9boVRMIVr+7LIo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mikulas Patocka , Dan Carpenter , Mike Snitzer , Nobuhiro Iwamatsu Subject: [PATCH 4.4 175/190] dm ioctl: fix out of bounds array access when no devices Date: Thu, 20 May 2021 11:23:59 +0200 Message-Id: <20210520092107.957446529@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092102.149300807@linuxfoundation.org> References: <20210520092102.149300807@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 [iwamatsu: Adjust context] Signed-off-by: Nobuhiro Iwamatsu 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 @@ -524,7 +524,7 @@ static int list_devices(struct dm_ioctl * Grab our output buffer. */ 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; }