Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp5026038rwb; Tue, 8 Aug 2023 19:10:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHWvt++1waWDvLIlQKqEHYlpfB0NR8/uicc3bN7N5DojzBuEXq/a5yE6RhiiRClVBDEv38y X-Received: by 2002:aa7:d04c:0:b0:523:9c4:544f with SMTP id n12-20020aa7d04c000000b0052309c4544fmr1215874edo.31.1691547020962; Tue, 08 Aug 2023 19:10:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691547020; cv=none; d=google.com; s=arc-20160816; b=z4klanzDwqlL4rjNsspcK8jANyQY81DXtlW/cC7Tsi6tYEF8ffCL3ecz5HZC9TszCa 1bf1cxMI2l2UQAqgH+GjldvDv5SWPpnQR1iC2/ZvNWoCDukGG4hhKqnDj/5ZevhAteOI HW7DFqoG5ULXAvpgWPQjimoEgYuihTIHbJhvyFnIJJKHprZELmVFXdeUXvx0FFmhUG3V cdNgM1Y5eJ3DaOOeGSSrXIWI2zip8aL63GZKqPNQdb4obwSoMr5rfVJfkyL/snoCX3Zf TzixbIoi9XcTNNxAsKad5027q5gXrRye8QzODAHZrrSP20UIXZUgQsBgd6la1hSBTCN2 8ucQ== 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 :message-id:date:subject:cc:to:from; bh=4ntPtzfeXLuO0xtV4sClO6Sj8KqX7DuWKDM+z3BIh80=; fh=WMLH40kHe7LZGd8CQYxzIMLJ4enLvVJrxhx2zSC3/0U=; b=dr3sXkIATsBWbV6W4BBK8aLXh29A0m+IzVNra9Yg7Yqja/hTv8m9lC1RBKgDSfseq/ 0SxqUnoF/qVS354snD6glYY36YND94Zt2ilKV/WwQcyKprtQ39Kuhi9WYWTv870UCnPR sJWdw0mu2EzpYeTVqdiDTHnMF6PPPRnhRaGM8nw87BoE2LDoDUBCvRM9xTASOlSi7jIw F+qDwW69nYzHBHV0jsfOO1+sZEEI5VKecdWhK1allJ0qYDDuFE8KHtyqU1Tz2vTzyrpm hm/+U56Ppnfx0GQGwQQWFagySmC6p953uEP94aFplDu6fBYyFqryH5/8oW4isspNR/xE SWeA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b16-20020a05640202d000b005234f302c99si698088edx.499.2023.08.08.19.09.56; Tue, 08 Aug 2023 19:10:20 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230157AbjHIBL3 (ORCPT + 99 others); Tue, 8 Aug 2023 21:11:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229793AbjHIBL2 (ORCPT ); Tue, 8 Aug 2023 21:11:28 -0400 Received: from mail.nfschina.com (unknown [42.101.60.195]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 8BF6D19A8; Tue, 8 Aug 2023 18:11:26 -0700 (PDT) Received: from localhost.localdomain (unknown [180.167.10.98]) by mail.nfschina.com (Maildata Gateway V2.8.8) with ESMTPA id 4C297608D10AB; Tue, 8 Aug 2023 17:19:10 +0800 (CST) X-MD-Sfrom: suhui@nfschina.com X-MD-SrcIP: 180.167.10.98 From: Su Hui To: jack@suse.cz, amir73il@gmail.com, repnop@google.com Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Su Hui Subject: [PATCH] fanotify: avoid possible NULL dereference Date: Tue, 8 Aug 2023 17:18:50 +0800 Message-Id: <20230808091849.505809-1-suhui@nfschina.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RDNS_NONE,SPF_HELO_NONE,SPF_PASS 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 smatch error: fs/notify/fanotify/fanotify_user.c:462 copy_fid_info_to_user(): we previously assumed 'fh' could be null (see line 421) Fixes: afc894c784c8 ("fanotify: Store fanotify handles differently") Signed-off-by: Su Hui --- fs/notify/fanotify/fanotify_user.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index f69c451018e3..5a5487ae2460 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -459,12 +459,13 @@ static int copy_fid_info_to_user(__kernel_fsid_t *fsid, struct fanotify_fh *fh, if (WARN_ON_ONCE(len < sizeof(handle))) return -EFAULT; - handle.handle_type = fh->type; handle.handle_bytes = fh_len; /* Mangle handle_type for bad file_handle */ if (!fh_len) handle.handle_type = FILEID_INVALID; + else + handle.handle_type = fh->type; if (copy_to_user(buf, &handle, sizeof(handle))) return -EFAULT; -- 2.30.2