Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp4471252rwb; Tue, 17 Jan 2023 01:01:01 -0800 (PST) X-Google-Smtp-Source: AMrXdXttEwrUiS5YnPmjq62QXMUIJAQb4R3mXXTqWk+YYMu4VwsLEzms7Ya7iCurT1zuVaRhhwZF X-Received: by 2002:a05:6a20:d399:b0:ac:6543:d515 with SMTP id iq25-20020a056a20d39900b000ac6543d515mr2438177pzb.42.1673946061070; Tue, 17 Jan 2023 01:01:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673946061; cv=none; d=google.com; s=arc-20160816; b=fv5LqpUGep3Gz/ZlFalipSdQe9QDz5/to9KPbMz/BTEo4Mjat2ScEiaoJTe5am3HwZ /lkYrxZz858Ga4cusAnzxeaXtlIAm9G9/H3AVQRCjMnrNaFo8Y4cfFNXimm/hHxgT5iB hWuBdznQS1eAd4pPnmku1cTIdlWTIEjTJN0rRr0xqeKkjMiCX+Nuqoc7DxbT1b8wVxlt To5hbepntoV+juojgWXYrd0ETbYcktpbUx/yHF8m/9Hg6sT5IQM+NxyJgvtmRCzlZ3bG /WaesXYhvCVOtk33BS3q0tECP/6emJpsuhRxL1op8DP8YPVdXVTB6MDjIYOKPQEkhQlg 4YxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=0iuG7PkMYKf7+8R4JHptOHZGwCBSRhIIXJ2tXnim9Ps=; b=zqpvrC/9mKxu1jH6sFr/eWGRKT07mxigi/UO5/d9RLG38ueHUwi5ekOyGft0c91SL/ qy5W89zSXma3mjorJ7I5ID6/euYKZSczwvbDJmyd0ypUzjB0pihe8C8cWWMOd6nPpD9f 1EkJcjkIExgu7WW0DZzyFNjEtD6jxNRZwevYt+V2CZxarsiVgBom7/4NdTU0yDtEwbns DY82t2w/WRZcqoSOukn8UyhV4k1Ln/GGTibVJS4qah4GOYeB0as7UfCxmB2IRQOA26E2 SXMTfgFvRITBfIYmZ2sDFiLAM/YNJeJRtnpP3vpYWx5KZ2DBdMRuR2r+nfQI6T7ggw8W cQ3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="NXJX/oGH"; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=m+2JALH6; 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 q9-20020a656a89000000b004a43c06daa0si33566782pgu.65.2023.01.17.01.00.55; Tue, 17 Jan 2023 01:01:01 -0800 (PST) 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=@suse.cz header.s=susede2_rsa header.b="NXJX/oGH"; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=m+2JALH6; 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 S236030AbjAQI1a (ORCPT + 49 others); Tue, 17 Jan 2023 03:27:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235811AbjAQI11 (ORCPT ); Tue, 17 Jan 2023 03:27:27 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 098A610C4; Tue, 17 Jan 2023 00:27:25 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8821E38128; Tue, 17 Jan 2023 08:27:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1673944044; 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=0iuG7PkMYKf7+8R4JHptOHZGwCBSRhIIXJ2tXnim9Ps=; b=NXJX/oGHZg/1ODfYgWCcmn+0wwahKQ7zQkXRd5DSD1mFUmbxeTWNWJ9JynfiA54gY3gsgT A0jT5X2CV4slDvfBntHDytf0JyN4M8tUzCO97VNpwARYJEmqu/iB5PS1eqm8ihKjP+yROz TGVleYHmmK6G0PLGwP9ur+XbG7/8n+o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1673944044; 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=0iuG7PkMYKf7+8R4JHptOHZGwCBSRhIIXJ2tXnim9Ps=; b=m+2JALH66lcQBqsBJFp+2YpheI9qlODjz1YCYeTugQ4orbs17m1hlVFr2Am4CoUB9w94VU E6i84SCD+FBiemCA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 796E11390C; Tue, 17 Jan 2023 08:27:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 4aCKHexbxmNxVQAAMHmgww (envelope-from ); Tue, 17 Jan 2023 08:27:24 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id BDF5FA06B2; Tue, 17 Jan 2023 09:27:23 +0100 (CET) Date: Tue, 17 Jan 2023 09:27:23 +0100 From: Jan Kara To: Richard Guy Briggs Cc: Jan Kara , Linux-Audit Mailing List , LKML , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, Paul Moore , Eric Paris , Steve Grubb , Amir Goldstein Subject: Re: [PATCH v5 2/3] fanotify: define struct members to hold response decision context Message-ID: <20230117082723.7g3ig6ernoslt7ub@quack3> References: <45da8423b9b1e8fc7abd68cd2269acff8cf9022a.1670606054.git.rgb@redhat.com> <20221216164342.ojcbdifdmafq5njw@quack3> <20230103124201.iopasddbtb6vi362@quack3> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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 On Mon 16-01-23 15:42:29, Richard Guy Briggs wrote: > On 2023-01-03 13:42, Jan Kara wrote: > > On Thu 22-12-22 15:47:21, Richard Guy Briggs wrote: > > > > > + > > > > > + if (info_len != sizeof(*friar)) > > > > > + return -EINVAL; > > > > > + > > > > > + if (copy_from_user(friar, info, sizeof(*friar))) > > > > > + return -EFAULT; > > > > > + > > > > > + if (friar->hdr.type != FAN_RESPONSE_INFO_AUDIT_RULE) > > > > > + return -EINVAL; > > > > > + if (friar->hdr.pad != 0) > > > > > + return -EINVAL; > > > > > + if (friar->hdr.len != sizeof(*friar)) > > > > > + return -EINVAL; > > > > > + > > > > > + return info_len; > > > > > +} > > > > > + > > > > > > > > ... > > > > > > > > > @@ -327,10 +359,18 @@ static int process_access_response(struct fsnotify_group *group, > > > > > return -EINVAL; > > > > > } > > > > > > > > > > - if (fd < 0) > > > > > + if ((response & FAN_AUDIT) && !FAN_GROUP_FLAG(group, FAN_ENABLE_AUDIT)) > > > > > return -EINVAL; > > > > > > > > > > - if ((response & FAN_AUDIT) && !FAN_GROUP_FLAG(group, FAN_ENABLE_AUDIT)) > > > > > + if (response & FAN_INFO) { > > > > > + ret = process_access_response_info(fd, info, info_len, &friar); > > > > > + if (ret < 0) > > > > > + return ret; > > > > > + } else { > > > > > + ret = 0; > > > > > + } > > > > > + > > > > > + if (fd < 0) > > > > > return -EINVAL; > > > > > > > > And here I'd do: > > > > > > > > if (fd == FAN_NOFD) > > > > return 0; > > > > if (fd < 0) > > > > return -EINVAL; > > > > > > > > As we talked in previous revisions we'd specialcase FAN_NOFD to just verify > > > > extra info is understood by the kernel so that application writing fanotify > > > > responses has a way to check which information it can provide to the > > > > kernel. > > > > > > The reason for including it in process_access_response_info() is to make > > > sure that it is included in the FAN_INFO case to detect this extension. > > > If it were included here > > > > I see what you're getting at now. So the condition > > > > if (fd == FAN_NOFD) > > return 0; > > > > needs to be moved into > > > > if (response & FAN_INFO) > > > > branch after process_access_response_info(). I still prefer to keep it > > outside of the process_access_response_info() function itself as it looks > > more logical to me. Does it address your concerns? > > Ok. Note that this does not return zero to userspace, since this > function's return value is added to the size of the struct > fanotify_response when there is no error. Right, good point. 0 is not a good return value in this case. > For that reason, I think it makes more sense to return -ENOENT, or some > other unused error code that fits, unless you think it is acceptable to > return sizeof(struct fanotify_response) when FAN_INFO is set to indicate > this. Yeah, my intention was to indicate "success" to userspace so I'd like to return whatever we return for the case when struct fanotify_response is accepted for a normal file descriptor - looks like info_len is the right value. Thanks! Honza -- Jan Kara SUSE Labs, CR