Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp5563481rwb; Tue, 17 Jan 2023 15:48:35 -0800 (PST) X-Google-Smtp-Source: AMrXdXvYtvpSnm9D6zLLHU2y4LDcU5IzYIKXSFnQ2xGAHPz68uQUtcyNE3PFS1ItLa9JegFID6Cw X-Received: by 2002:a17:903:2789:b0:188:bd82:2b7c with SMTP id jw9-20020a170903278900b00188bd822b7cmr5365843plb.5.1673999315718; Tue, 17 Jan 2023 15:48:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673999315; cv=none; d=google.com; s=arc-20160816; b=vzsiY+bxsL4IR9RyDnlXM3deRqvoNv7ahrisHjAfeeLhhr6AVJi2qypRnc94pZA9Hn KCoCkG2nkamsFY45L77HJVdbPJeZgvnWbau0Gnnd+Z+mDNi/TBMxjXswLAw3ETf2kaFe pQazki9EXLbuXGJjR9+g/CcKkz8lCHEQx0qwwBFN7bouhD4kE/AgdshDI8dkaQnycOwC BjDDg+LNzWijhXcy/PmFep+2AB7SLZqYGRBc7mCfy7FFfSpg98Ori8HmtgYJw/MQN4RI YLI4AjcWrK3qTaoTBDsXmsm1xEhJaNLuVTwKvL9Y+K9VtueItC+Aq++qT7vvnkSN0h91 /Gsg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yodz909gQLcsaRT2R9pZz/clnDYmt0URiuiWmBb/3AM=; b=O3btFtxiGfNHala/+qbHUca4wVqdO30UoBiw78RJmNi7SByXtRg9FmGDzQb0d1tD0f L0LAjzKKPGnPXZm8DUi8/LnOFLpuuJ8LWZLE4Fkq5neAY58sc072V+hKDYPxY33ATHte 84s5hB/2u1OOqAGIEAqPur6gArqsNZYuhOGUYB+baMxbCW531fjD2tzOPfa8zHZqA2Vz OzKr510GGjH/MnFJYpu405e8GWSEwB3KvPyA3IAldNqGurug8L+/o5ZrOot7ZvVJMU1S BLiIBiRG77dGybiIyuBN7xCoESsz///IIz/T7ObDmOjUhX9P+9Jtw3CbqOFe8rgCN7NP hyYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HwFWa709; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u6-20020a170903124600b001944ad088c9si23739571plh.240.2023.01.17.15.48.30; Tue, 17 Jan 2023 15:48:35 -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=@redhat.com header.s=mimecast20190719 header.b=HwFWa709; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229933AbjAQXYO (ORCPT + 46 others); Tue, 17 Jan 2023 18:24:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229820AbjAQXXr (ORCPT ); Tue, 17 Jan 2023 18:23:47 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1E5D6D367 for ; Tue, 17 Jan 2023 13:14:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673990065; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yodz909gQLcsaRT2R9pZz/clnDYmt0URiuiWmBb/3AM=; b=HwFWa709wtgnAcvwfxgXdTqjTwS2KDHl9uW10ZqP+0FinoSvo6A6LzDOGGIRBf/3z9J/Ld X2nLSQb2Vz1mREUbeH8tyKlfzUtNK6hKrdT3C07kjYtFqtFI7lZfayP1iyo74cY908ifyA 49jecRSYoKDjqt7IbYSE2vQ5uYiUVZw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-186-BoeEghyRO82Zx9XgaupITw-1; Tue, 17 Jan 2023 16:14:21 -0500 X-MC-Unique: BoeEghyRO82Zx9XgaupITw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9B23D8A0101; Tue, 17 Jan 2023 21:14:20 +0000 (UTC) Received: from madcap2.tricolour.com (ovpn-0-3.rdu2.redhat.com [10.22.0.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3AA47C15BAD; Tue, 17 Jan 2023 21:14:19 +0000 (UTC) From: Richard Guy Briggs To: Linux-Audit Mailing List , LKML , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org Cc: Paul Moore , Eric Paris , Steve Grubb , Richard Guy Briggs , Jan Kara , Amir Goldstein Subject: [PATCH v6 1/3] fanotify: Ensure consistent variable type for response Date: Tue, 17 Jan 2023 16:14:05 -0500 Message-Id: <3778cb0b3501bc4e686ba7770b20eb9ab0506cf4.1673989212.git.rgb@redhat.com> In-Reply-To: References: MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 The user space API for the response variable is __u32. This patch makes sure that the whole path through the kernel uses u32 so that there is no sign extension or truncation of the user space response. Suggested-by: Steve Grubb Link: https://lore.kernel.org/r/12617626.uLZWGnKmhe@x2 Signed-off-by: Richard Guy Briggs Acked-by: Paul Moore --- fs/notify/fanotify/fanotify.h | 2 +- fs/notify/fanotify/fanotify_user.c | 6 +++--- include/linux/audit.h | 6 +++--- kernel/auditsc.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index 57f51a9a3015..f899d610bc08 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -425,7 +425,7 @@ FANOTIFY_PE(struct fanotify_event *event) struct fanotify_perm_event { struct fanotify_event fae; struct path path; - unsigned short response; /* userspace answer to the event */ + u32 response; /* userspace answer to the event */ unsigned short state; /* state of the event */ int fd; /* fd we passed to userspace for this event */ }; diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 4546da4a54f9..caa1211bac8c 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -289,7 +289,7 @@ static int create_fd(struct fsnotify_group *group, const struct path *path, */ static void finish_permission_event(struct fsnotify_group *group, struct fanotify_perm_event *event, - unsigned int response) + u32 response) __releases(&group->notification_lock) { bool destroy = false; @@ -310,9 +310,9 @@ static int process_access_response(struct fsnotify_group *group, { struct fanotify_perm_event *event; int fd = response_struct->fd; - int response = response_struct->response; + u32 response = response_struct->response; - pr_debug("%s: group=%p fd=%d response=%d\n", __func__, group, + pr_debug("%s: group=%p fd=%d response=%u\n", __func__, group, fd, response); /* * make sure the response is valid, if invalid we do nothing and either diff --git a/include/linux/audit.h b/include/linux/audit.h index 3608992848d3..d6b7d0c7ce43 100644 --- a/include/linux/audit.h +++ b/include/linux/audit.h @@ -416,7 +416,7 @@ extern void __audit_log_capset(const struct cred *new, const struct cred *old); extern void __audit_mmap_fd(int fd, int flags); extern void __audit_openat2_how(struct open_how *how); extern void __audit_log_kern_module(char *name); -extern void __audit_fanotify(unsigned int response); +extern void __audit_fanotify(u32 response); extern void __audit_tk_injoffset(struct timespec64 offset); extern void __audit_ntp_log(const struct audit_ntp_data *ad); extern void __audit_log_nfcfg(const char *name, u8 af, unsigned int nentries, @@ -523,7 +523,7 @@ static inline void audit_log_kern_module(char *name) __audit_log_kern_module(name); } -static inline void audit_fanotify(unsigned int response) +static inline void audit_fanotify(u32 response) { if (!audit_dummy_context()) __audit_fanotify(response); @@ -679,7 +679,7 @@ static inline void audit_log_kern_module(char *name) { } -static inline void audit_fanotify(unsigned int response) +static inline void audit_fanotify(u32 response) { } static inline void audit_tk_injoffset(struct timespec64 offset) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 547c88be8a28..d1fb821de104 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2877,7 +2877,7 @@ void __audit_log_kern_module(char *name) context->type = AUDIT_KERN_MODULE; } -void __audit_fanotify(unsigned int response) +void __audit_fanotify(u32 response) { audit_log(audit_context(), GFP_KERNEL, AUDIT_FANOTIFY, "resp=%u", response); -- 2.27.0