Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp555040rwa; Sat, 20 Aug 2022 08:54:51 -0700 (PDT) X-Google-Smtp-Source: AA6agR5Awdm80UW6bbeBgxcEmfJRLUxhFfVDDsi6FVMjzU88unsahrG+qLWYLdBJPPAkcyIPii4J X-Received: by 2002:a63:da13:0:b0:42a:7f03:a00e with SMTP id c19-20020a63da13000000b0042a7f03a00emr1502485pgh.332.1661010890958; Sat, 20 Aug 2022 08:54:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661010890; cv=none; d=google.com; s=arc-20160816; b=pIYvWtOvhUo3VGrfq/INIjIBMUL3gSl79BlkpneiphYHSeCYOaEtV4QAIfb+IZjCo0 KB5+z44cUbdDNTZNQuAFZccV/mLPHqidE+tqdB0QcYW9xKF4Cit1oKgn/vGZ52wT7ksG WWE7sAVvlPr+pjBw3OkDlpU95rV5dUqz24r+mQorK0/BRX2TnB+H3Kar8bIjIlzpmI2x 9lH4HbBwNLJKeF2PGjvjLnTr9NHbHdMc8sU9ZBZ68V3EjjQBXit48DB/uzrmnteSus4+ /k+qQUJvU9EHJYzmBPKG0ZrXrM7+wpVLhrChIBXUd5g6zsrue39Jd5RajSkz5Wtkh3ns YnFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:date:cc:to:from:subject:message-id; bh=rYGgoDy5IaJhZfjObFc78Lu8HznKyz5P+zAMheYkm0w=; b=HK4E2nv7JaqWtFmFBUrTUzRmj/wXPEY56qjP2yvxvORW7yY+ssfEO4/p5fz6OWygO4 OvDGhECeKNrAmskRHn8kDflzCaSNaU7ks7UgMZMubP5JxacGltDcpNS712IZqyQzhqj1 dqlidPpb4gHejXDMN+67RqLpXqp7VGbKa7XfYv3is3c/A8N62WuARIawQWLpsG9xHmwG ppo8F4aUcF6ip/EgcP2t+Ad+qvuWepQ+loYUx7rSSGjOA3FrP0V3e88jBT3rCxFQdrdn AsXYZicE7Su/OqseplvqIXbfOB+rmhJbDTw+KInMYcs46WWxC4T6pebcXf3I3B2Kd1nq FI/Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c6-20020a63ea06000000b0041d109766a7si7254154pgi.529.2022.08.20.08.54.31; Sat, 20 Aug 2022 08:54:50 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345327AbiHTPbZ convert rfc822-to-8bit (ORCPT + 99 others); Sat, 20 Aug 2022 11:31:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229605AbiHTPbW (ORCPT ); Sat, 20 Aug 2022 11:31:22 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4B867697A for ; Sat, 20 Aug 2022 08:31:21 -0700 (PDT) Received: from [192.168.0.105] (unknown [136.169.224.60]) by mail.ispras.ru (Postfix) with ESMTPSA id CFF9740D403D; Sat, 20 Aug 2022 15:31:19 +0000 (UTC) Message-ID: <6228a437bb9d7f677f5e97973518bcd555bc2a07.camel@ispras.ru> Subject: [POSSIBLE BUG] Dereferencing of NULL pointer From: Rustam Subkhankulov To: Juergen Gross Cc: Stefano Stabellini , Oleksandr Tyshchenko , xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, Alexey Khoroshilov , ldv-project@linuxtesting.org Date: Sat, 20 Aug 2022 20:30:56 +0300 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.44.1-0ubuntu1 MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 Version: 6.0-rc1 Description: In function 'privcmd_ioctl_dm_op' (drivers/xen/privcmd.c: 615)return value of 'kcalloc' with GFP_KERNEL flag is assigned to "pages" variable. GFP_KERNEL flag does not guarantee, that the return value will not be NULL. In that case, there is a jump to the "out" label. --------------------------------------------------------------------- 667 pages = kcalloc(nr_pages, sizeof(*pages), GFP_KERNEL); 668 if (!pages) { 669 rc = -ENOMEM; 670 goto out; 671 } --------------------------------------------------------------------- Variable 'pages' is passed to function 'unpin_user_pages_dirty_lock' as 1st parameter at [drivers/xen/privcmd.c: 695]. --------------------------------------------------------------------- 694 out: 695 unlock_pages(pages, nr_pages); --------------------------------------------------------------------- Then, variable 'pages' is passed to function 'unpin_user_pages_dirty_lock' as 1st parameter at [drivers/xen/privcmd.c: 612]. --------------------------------------------------------------------- 610 static void unlock_pages(struct page *pages[], unsigned int nr_pages) 611 { 612 unpin_user_pages_dirty_lock(pages, nr_pages, true); 613 } --------------------------------------------------------------------- 'pages' and 'npages' are passed as parameters to function 'sanity_check_pinned_pages' at [mm/gup.c: 311]. --------------------------------------------------------------------- 299 void unpin_user_pages_dirty_lock(struct page **pages, unsigned long npages, 300 bool make_dirty) 301 { 302 unsigned long i; 303 struct folio *folio; 304 unsigned int nr; 305 306 if (!make_dirty) { 307 unpin_user_pages(pages, npages); 308 return; 309 } 310 311 sanity_check_pinned_pages(pages, npages); --------------------------------------------------------------------- In function 'sanity_check_pinned_pages', if (IS_ENABLED(CONFIG_DEBUG_VM)) and (npages > 0), NULL pointer 'pages' is dereferenced at [mm/gup.c: 51]. --------------------------------------------------------------------- 32 static inline void sanity_check_pinned_pages(struct page **pages, 33 unsigned long npages) 34 { 35 if (!IS_ENABLED(CONFIG_DEBUG_VM)) 36 return; .. 50 for (; npages; npages--, pages++) { 51 struct page *page = *pages; ^^^^^^ ^ --------------------------------------------------------------------- Else if (!IS_ENABLED(CONFIG_DEBUG_VM)) and (npages > 0) function 'gup_folio_next' is called with 'pages' and 'npages' as parameters at [mm/gup.c: 311]. --------------------------------------------------------------------- 312 for (i = 0; i < npages; i += nr) { 313 folio = gup_folio_next(pages, npages, i, &nr); --------------------------------------------------------------------- In function 'gup_folio_next' NULL pointer 'list' is dereferenced at [mm/gup.c: 263]. --------------------------------------------------------------------- 262 static inline struct folio *gup_folio_next(struct page **list, 263 unsigned long npages, unsigned long i, unsigned int *ntails) 264 { 265 struct folio *folio = page_folio(list[i]); ^^^^^^^^^ ---------------------------------------------------------------------