Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1002161pxb; Wed, 6 Apr 2022 06:28:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEchqGLlFIDYa/MtB4d1lhT70KtxxvJO9z6ArSKdByoaiBSuKAWCzPTx579r6EBPgtac8v X-Received: by 2002:a17:902:f212:b0:156:a80c:e10d with SMTP id m18-20020a170902f21200b00156a80ce10dmr8608614plc.11.1649251687177; Wed, 06 Apr 2022 06:28:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649251687; cv=none; d=google.com; s=arc-20160816; b=VDq6SJwfH3IPGvbS3sBFNydWKAzTZwuga8EHAwxnygNfsyuhA2WPnegx7hWIvVoqmP P+HqFx7sELi9ODYB5JMFyTsWOIc19USyIY/Uj6ixdwC93HLEy5Yzwgv/cmDuxF5/vf6o jkCJ7vtGkKE2sXT3P9STfrE1bDgJNq16tdkvG34Gzpq/kuxqsVMKB/iptTPWGM0UP2tf a0N2t28eH62MDo6cPVzBtZNMDgG3hKb5wHSgH52vigPWpxT1h030uge+nKRponQDofzj O3puAWHRfI4rSAFoSTIqsBXcgqfYg5SpA9ka0y28kHoFFjpqC5rJcrciYloX0HASLikc ELdA== 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=S27hIcDzZp8BQTu03aZyDqUeEHbpJmNkFifVDYGe7KZLvDp/+G8hNUorWXc1KWJEIz rvIdcQsKTUyWvxnw7FFlRVFJ1pW9iNWjYg/+gQNwRjGYJiVpThSOU1ow17BA8kz1o/XA sJnIpn7DAWQzAtiLO45v5SKo0WSUQh7uK2a9nQk7ipD8DmloFYQhV4OSykw6TuU9vvst r2NqQCEV7GrY10YXuSgA+6lTxbltJfgQdkMiSbZH+TCGPUbbu4MTjHr6nAMBWmU6CcWv hOd7z/kCKKvZUUrbNN5XInZlZ6pu8NQ9QPjauH6oG03sihJUYSYJ3pnybpt+jj6WciFg KQPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hi0uxZeq; 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 i21-20020aa78b55000000b004fa3a8e0062si14256214pfd.281.2022.04.06.06.28.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 06:28:07 -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=hi0uxZeq; 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 80F8F537796; Wed, 6 Apr 2022 04:09:42 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1843037AbiDFBi6 (ORCPT + 99 others); Tue, 5 Apr 2022 21:38:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348812AbiDEJsi (ORCPT ); Tue, 5 Apr 2022 05:48:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC9AC95A36; Tue, 5 Apr 2022 02:35:58 -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 48419615E5; Tue, 5 Apr 2022 09:35:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F77DC385A0; Tue, 5 Apr 2022 09:35:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649151357; bh=hE0+M1yHyMNF+b58TMcf0wEYVHccPRvtpndBkcpj1nU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hi0uxZeq+nukjseWr2Ug73wXu/b72jncipxVpywC2ormglUG9kWBsYpP50Aizz5RT 6NBVusC0vn0giAyFXDQaoMzTdLi/RXER4TjsJwfYv5Y+CRVTYjG/oLH0yFKnn/GalT DNgnddgpIAIGKoRkRbvu5do64gmwwDclS7/Eclos= 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.15 387/913] udmabuf: validate ubuf->pagecount Date: Tue, 5 Apr 2022 09:24:09 +0200 Message-Id: <20220405070351.447460224@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@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