Message ID | 20230808091849.505809-1-suhui@nfschina.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2507365vqr; Tue, 8 Aug 2023 18:53:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGevB/QkoQXHXt5p5BINF/K/9sUVpi/Ugjyn7x3xkmxJ70bOhCpnH74pn84wAe+qUXeYYey X-Received: by 2002:a05:6358:2606:b0:134:e422:c500 with SMTP id l6-20020a056358260600b00134e422c500mr1383125rwc.27.1691546020952; Tue, 08 Aug 2023 18:53:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691546020; cv=none; d=google.com; s=arc-20160816; b=y9xFzban5tX10mUO7l6VGBCJ9efZqKQuAkdKSARTIQgwS4J9DKeObd4W8Fn1kpgv6w ptTaadBlA82/9vXmlRrLSTt478t9EtDF6/X4U4WlOGmA2MGiQYRqFVsPTupflGnsMg+p lLOyd5fbOIL3/k7aB5eVKpTw8tY5cs/H2nOAdeJq90XNX2rde9Dune/5mBf3isHzvpmm EA5AxGmifGApdQwEq9hV3TgxeEjHJk/4tBku0M2rZQH86yHGKa73pU01M9ybpqNXxelT x4TXU1z1ABAdB1HOunzmvouEQRFeKW/z9rD1AAydt3OlryVs6UB5i8eWS2TKtrSjnDhY n/zA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k7-20020a633d07000000b00564bcae8b4dsi7846750pga.61.2023.08.08.18.53.28; Tue, 08 Aug 2023 18:53:40 -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 S230206AbjHIBL3 (ORCPT <rfc822;aaronkmseo@gmail.com> + 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <suhui@nfschina.com> 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 <suhui@nfschina.com> 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773714560492581120 X-GMAIL-MSGID: 1773714560492581120 |
Series |
fanotify: avoid possible NULL dereference
|
|
Commit Message
Su Hui
Aug. 8, 2023, 9:18 a.m. UTC
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 <suhui@nfschina.com>
---
fs/notify/fanotify/fanotify_user.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
On Tue, Aug 8, 2023 at 12:19 PM Su Hui <suhui@nfschina.com> wrote: > > 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 <suhui@nfschina.com>' Reviewed-by: Amir Goldstein <amir73il@gmail.com> > --- > 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 >
On Thu 10-08-23 20:58:16, Amir Goldstein wrote: > On Tue, Aug 8, 2023 at 12:19 PM Su Hui <suhui@nfschina.com> wrote: > > > > 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 <suhui@nfschina.com>' > > Reviewed-by: Amir Goldstein <amir73il@gmail.com> I'm sorry but this has somehow fallen through the cracks. > > 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; Well, if passed 'fh' is NULL, we have problems later in the function anyway. E.g. in fanotify_fh_buf() a few lines below. So I think this needs a bit more work that just this small fixup... Honza > > > > /* 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 > >
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;