Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp416305pxt; Thu, 5 Aug 2021 02:57:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycI2WX7EY53y7yF2MgCpgqzLLxNhnNraMe5L18KSCk4jt38aSwWCgRatXDlrq70RKCet5u X-Received: by 2002:aa7:d709:: with SMTP id t9mr5268356edq.384.1628157444474; Thu, 05 Aug 2021 02:57:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628157444; cv=none; d=google.com; s=arc-20160816; b=qMiPogk6oAMn2Vy7scut8qJDtoYtWO/AUl7JS/ri2yo8UY1xF65lqdpvXK/T6PM5Vo ouWYhQkQQN4APw8p+A4Va0VVGLt78mgNeG2HMK4UgB0Kly3DT48oEgx9oLyaHI/e8rmU 1hh+3fKVyMCbGtMEyn77WeJC2b23BBTUeGFJGpCQ+8qrsever0XvWDYRpc6svBEJkGiW v+VLPjswUso28lLC5wlmSWnr6DWFa1kgKcC8jAfEDy2gwsRX8AMn1VtIvEHGDTIXsCgG uqGl8JR1KGh/M3LObAtEZt7B5SuaQaXr/36XJpEV9s9laeQxThi48H43+YZ949dVhn2N JvTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-signature; bh=gfY4K5+0+7vBrDy12tOrfA0yGsug6efsrXkibuaP9XI=; b=r8Plkci8nIxP0jnVAI5RuezBx43OZa4Kaw1JCtHyLRpvY3JBN2qQVSP462FEZzLKnV x0h9Zs1te3DOoJ/+ifPNq6XVFZ4dk944Dnl5Cc4ryovPdSUImT5F5Q2Bz96viLTKB5vX /bOS2dWGEYcLybmXr/tPH08OySCuliHnJrekpwahyl4490UHr3aI4B+B2p+s6g/pYc7w wbKMbtzfapelpXadO8nr3JnXdqfcCBcY+SsHiXE0NFhacnNP6jUecnhN3SsYbbgZxkF1 6WxaRUIrf912EWH266zZDfSYEQYYQjgGX47IvqYyjh5Y+T1QWbGXsD2kTI1rbQbkNZJf dFlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=JXs0cuhM; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y4si5371005edt.434.2021.08.05.02.56.52; Thu, 05 Aug 2021 02:57:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=JXs0cuhM; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239930AbhHEJ4e (ORCPT + 99 others); Thu, 5 Aug 2021 05:56:34 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:57638 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232930AbhHEJ4e (ORCPT ); Thu, 5 Aug 2021 05:56:34 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 0F6971FE42; Thu, 5 Aug 2021 09:56:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1628157379; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gfY4K5+0+7vBrDy12tOrfA0yGsug6efsrXkibuaP9XI=; b=JXs0cuhMxm04010Ez7oiVyiCph0E6fkmVywfD0VoCTkiTRA/YAbvcDTE5y9EgOsxQ+kBEZ J/3yBu1Cxh6pE/CVUF73KLqUbbLJddXAgGdnIbr+hs/Pa/jRALH+0Q7+P5NXf4lTIz7L1e 1smJeMD2RRsGBcpkd23tR7TZtDnG10M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1628157379; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gfY4K5+0+7vBrDy12tOrfA0yGsug6efsrXkibuaP9XI=; b=1ATS2f59ObC+xHetWqfLT8aEi+uTOKZapPrHYShJAxRX9Dv5JperNSmbGCAFaIHIzX5pTP N0Ju1Vct6EjUlcDw== Received: from quack2.suse.cz (unknown [10.163.43.118]) by relay2.suse.de (Postfix) with ESMTP id E4317A3B94; Thu, 5 Aug 2021 09:56:18 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id BB2A41E1511; Thu, 5 Aug 2021 11:56:18 +0200 (CEST) Date: Thu, 5 Aug 2021 11:56:18 +0200 From: Jan Kara To: Gabriel Krisman Bertazi Cc: jack@suse.com, amir73il@gmail.com, djwong@kernel.org, tytso@mit.edu, david@fromorbit.com, dhowells@redhat.com, khazhy@google.com, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-api@vger.kernel.org, kernel@collabora.com Subject: Re: [PATCH v5 14/23] fanotify: Encode invalid file handler when no inode is provided Message-ID: <20210805095618.GF14483@quack2.suse.cz> References: <20210804160612.3575505-1-krisman@collabora.com> <20210804160612.3575505-15-krisman@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210804160612.3575505-15-krisman@collabora.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Wed 04-08-21 12:06:03, Gabriel Krisman Bertazi wrote: > Instead of failing, encode an invalid file handler in fanotify_encode_fh > if no inode is provided. This bogus file handler will be reported by > FAN_FS_ERROR for non-inode errors. > > Also adjust the single caller that might rely on failure after passing > an empty inode. It is not 'file handler' but rather 'file handle' - several times in the changelog and in subject :). > Suggested-by: Amir Goldstein > Signed-off-by: Gabriel Krisman Bertazi > --- > fs/notify/fanotify/fanotify.c | 39 ++++++++++++++++++++--------------- > fs/notify/fanotify/fanotify.h | 6 ++++-- > 2 files changed, 26 insertions(+), 19 deletions(-) > > diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c > index 0d6ba218bc01..456c60107d88 100644 > --- a/fs/notify/fanotify/fanotify.c > +++ b/fs/notify/fanotify/fanotify.c > @@ -349,12 +349,6 @@ static int fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, > void *buf = fh->buf; > int err; > > - fh->type = FILEID_ROOT; > - fh->len = 0; > - fh->flags = 0; > - if (!inode) > - return 0; > - I'd keep the fh->flags initialization here. Otherwise it will not be initialized on some error returns. > @@ -363,8 +357,9 @@ static int fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, > if (fh_len < 4 || WARN_ON_ONCE(fh_len % 4)) > goto out_err; > > - /* No external buffer in a variable size allocated fh */ > - if (gfp && fh_len > FANOTIFY_INLINE_FH_LEN) { > + fh->flags = 0; > + /* No external buffer in a variable size allocated fh or null fh */ > + if (inode && gfp && fh_len > FANOTIFY_INLINE_FH_LEN) { > /* Treat failure to allocate fh as failure to encode fh */ > err = -ENOMEM; > ext_buf = kmalloc(fh_len, gfp); > @@ -376,14 +371,24 @@ static int fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, > fh->flags |= FANOTIFY_FH_FLAG_EXT_BUF; > } > > - dwords = fh_len >> 2; > - type = exportfs_encode_inode_fh(inode, buf, &dwords, NULL); > - err = -EINVAL; > - if (!type || type == FILEID_INVALID || fh_len != dwords << 2) > - goto out_err; > - > - fh->type = type; > - fh->len = fh_len; > + if (inode) { > + dwords = fh_len >> 2; > + type = exportfs_encode_inode_fh(inode, buf, &dwords, NULL); > + err = -EINVAL; > + if (!type || type == FILEID_INVALID || fh_len != dwords << 2) > + goto out_err; > + fh->type = type; > + fh->len = fh_len; > + } else { > + /* > + * Invalid FHs are used on FAN_FS_ERROR for errors not > + * linked to any inode. Caller needs to guarantee the fh > + * has at least FANOTIFY_NULL_FH_LEN bytes of space. > + */ > + fh->type = FILEID_INVALID; > + fh->len = FANOTIFY_NULL_FH_LEN; > + memset(buf, 0, FANOTIFY_NULL_FH_LEN); > + } Maybe it will become clearer later during the series but why do you set fh->len to FANOTIFY_NULL_FH_LEN and not 0? Honza -- Jan Kara SUSE Labs, CR