Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp651573pxb; Tue, 5 Apr 2022 17:21:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2ATukyJ94d89wp8GlcYaCJFLpbDBrrzSzn5CS23f7R6PVzc8WWUdvGeHO+ShBBM8H1569 X-Received: by 2002:a05:6402:54:b0:419:9b58:e305 with SMTP id f20-20020a056402005400b004199b58e305mr6039826edu.158.1649204502895; Tue, 05 Apr 2022 17:21:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649204502; cv=none; d=google.com; s=arc-20160816; b=j7hEcXNBmGejEC01MiHAi14mLVNNrtrn02VZ2keoEJQ/gYRWp+T47Ak0BeW3OTuydm 6sGRUIj77FfF+UhFWrZj6G8T2r+ktuAfqCYqCWMHx+2vythKteye+qBVHMeqLcCl5Lat FnwRCtKS97FRYCURQS0twOOv7ekmHlRqwEKJpw+iVxXhPjpBR9tgR7DSd79UQGm8oobS HZiTZ3Wk+ZATKlLIAbzUl02l8zzW2iVemCuptmp8VokN1mbLfMHc4WZooaUkxJB9KQi7 iUg7aJ/mZahO1VGoeEaUWjfKSDhpANhrkrovE4tKhxv71Rb5MxJ03dc6xJLbFElmTJTB /R8w== 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=X+6Eo6u0lF8TiL3lfd1aeyalCJs3mC0j9FPKr2RqxgN/GsJXaeArE5BNjGv7zhHBhY QwvuFAC0zeWzyicl5vvM5z17sl4ZC1TIOBnYK9rz6WaYoaWG0ySmkDs/RrAherKcySr7 swogqFoMd/YCXy5gn36hccNfBAckyvwDszZlpodwKb4yWFMo54D7UfWMXZJ8QvGIbcDC FAOYQIeD1KdqT+TfQBtk7kmK9IjFnruJ+liz3MgMb1qTDVO+MkdARaj5ygKY7nfOCugT 1exCxFQ0fV/qo2zi7ZZhePi8P9cVBDLPF7o2oytx7FFegpbJnY+WuaZfZCJKDCjl6yic HOew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zbc8j0B1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u11-20020a50d94b000000b00418f551af69si9739904edj.232.2022.04.05.17.21.11; Tue, 05 Apr 2022 17:21:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zbc8j0B1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1381163AbiDEL6t (ORCPT + 99 others); Tue, 5 Apr 2022 07:58:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245028AbiDEIxC (ORCPT ); Tue, 5 Apr 2022 04:53:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B231DC9; Tue, 5 Apr 2022 01:49:53 -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 073B261504; Tue, 5 Apr 2022 08:49:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AD22C385A4; Tue, 5 Apr 2022 08:49:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649148592; bh=hE0+M1yHyMNF+b58TMcf0wEYVHccPRvtpndBkcpj1nU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zbc8j0B1nxD0RGBtrwOpT3aBZvEi0ZwSTNfFTVndvub1ZVgFxByaLxmfq4IAxsnWv RszGCXHAIosM99gMg1Bz9FNmTqtTDtMaGVll4oEjnxnBIy7aToTAOzic4xI4QTRvGk XfL8w2wgpe7+5jS4aZuS7iXDUr5LqvtZerL3rwC4= 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.16 0411/1017] udmabuf: validate ubuf->pagecount Date: Tue, 5 Apr 2022 09:22:04 +0200 Message-Id: <20220405070406.487545541@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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