Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp746027pxb; Tue, 5 Apr 2022 21:29:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMhxMam4idb48tuAklESS1j9PBEPBO/XMF7PMH05g9hLC8b4m5+G3YV1+0MbsAverGaAF8 X-Received: by 2002:a63:fd01:0:b0:381:31b7:8bc5 with SMTP id d1-20020a63fd01000000b0038131b78bc5mr5532656pgh.206.1649219392996; Tue, 05 Apr 2022 21:29:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649219392; cv=none; d=google.com; s=arc-20160816; b=Wsz8nuQBN2jTyA6pzFhZxTa8cDaEPJPx6EDv9b4JKT0M1MG5vAXO3tiDEgkrNNEZ1K Zp+3+BADX1Ya47l1MOZjY3Hv2OCgPhR4mgE0qZbytCAfbcni7kMXWpK7JsTXdIy4kvVz JNN4tq20pq+ZRNqz2T0L7E77BEoH9hn/YhOqTuke/sJNY5qxrV/XxfQnZzhqfwi6a51q H+IKXzrNYHVGIfQfUB9SRqH2zriCkSn3RpfnkZe4X3JNpkceDPlMB+4jgdLqwK5ZEsLh spf8ykUpBd9+gODzLeQY2uBSMMCVmijv1gFrcCoWEwouE1c9FY+JxWh/jFZa8G68a05R vCfQ== 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=No8sbK2RNFPf7arNwkKt5wTo+ptPhcl3OpAdHfbVXfc=; b=0xDMAbBi+L0vLdej0CyARmHCwpvn79daPyjpxkTfkZrry9m7jK7CuBBEvmxYyj5FA7 vLQ3FeiKIlfKXrUJpY9ChMI67GAud4urfJ6SiINug8H296CGNOWELiE6Fj477VcmHo9a lv3kLVNiHzbcCIDKgRGJqxdNk75RrKxdufSNylWULtn8rOXmHZWmwy2fZPn2M0FsEg/p C4UuwU3pDa6hR3yf6GZ/78BLuLwp+Ai9P0Booek1YKdm/oLw2srz3BbRcnKvIRHuyW/u wKZSFnWjgO3dmxcrcdfIOsZMvSAmIGHIx78rCQ5/QRzXM4nxzv52f+seThRTAZKO4uBq Q3mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Cg5wWAfc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b11-20020a170902d88b00b00153b2d165a5si13702105plz.429.2022.04.05.21.29.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 21:29:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Cg5wWAfc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 936FD179B18; Tue, 5 Apr 2022 19:52:38 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235869AbiDEIke (ORCPT + 99 others); Tue, 5 Apr 2022 04:40:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235936AbiDEIAt (ORCPT ); Tue, 5 Apr 2022 04:00:49 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7850F49243; Tue, 5 Apr 2022 00:58:51 -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 ams.source.kernel.org (Postfix) with ESMTPS id 34634B81B16; Tue, 5 Apr 2022 07:58:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A13B9C340EE; Tue, 5 Apr 2022 07:58:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649145529; bh=hE0+M1yHyMNF+b58TMcf0wEYVHccPRvtpndBkcpj1nU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cg5wWAfcUUXd8L9OpKNK2ccxc7S9haPIiUwXqjjqcZwJr6KzqqoP1TIZhjrkBPfam bgTLRJb86QdPfhu9dCB3rJDgu3dGLlDLp9Dvc3Yx7f2RKJtnI8RxSQtLYZKW7+oaxr z0/6c8DJE7Kwu8nveUjinFimSacGboz/UwACTXEQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Skripkin , Gerd Hoffmann , Sasha Levin , syzbot+2c56b725ec547fa9cb29@syzkaller.appspotmail.com Subject: [PATCH 5.17 0439/1126] udmabuf: validate ubuf->pagecount Date: Tue, 5 Apr 2022 09:19:46 +0200 Message-Id: <20220405070420.510003967@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@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.0 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,T_SCC_BODY_TEXT_LINE autolearn=no 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: Pavel Skripkin [ Upstream commit 2b6dd600dd72573c23ea180b5b0b2f1813405882 ] Syzbot has reported GPF in sg_alloc_append_table_from_pages(). The problem was in ubuf->pages == ZERO_PTR. ubuf->pagecount is calculated from arguments passed from user-space. If user creates udmabuf with list.size == 0 then ubuf->pagecount will be also equal to zero; it causes kmalloc_array() to return ZERO_PTR. Fix it by validating ubuf->pagecount before passing it to kmalloc_array(). Fixes: fbb0de795078 ("Add udmabuf misc device") Reported-and-tested-by: syzbot+2c56b725ec547fa9cb29@syzkaller.appspotmail.com Signed-off-by: Pavel Skripkin Link: http://patchwork.freedesktop.org/patch/msgid/20211230142649.23022-1-paskripkin@gmail.com Signed-off-by: Gerd Hoffmann Signed-off-by: Sasha Levin --- drivers/dma-buf/udmabuf.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index c57a609db75b..e7330684d3b8 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -190,6 +190,10 @@ static long udmabuf_create(struct miscdevice *device, if (ubuf->pagecount > pglimit) goto err; } + + if (!ubuf->pagecount) + goto err; + ubuf->pages = kmalloc_array(ubuf->pagecount, sizeof(*ubuf->pages), GFP_KERNEL); if (!ubuf->pages) { -- 2.34.1