From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DA55C4338F for ; Mon, 2 Aug 2021 21:47:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6ECCE60EBB for ; Mon, 2 Aug 2021 21:47:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231656AbhHBVrP (ORCPT ); Mon, 2 Aug 2021 17:47:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229567AbhHBVrP (ORCPT ); Mon, 2 Aug 2021 17:47:15 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5208EC06175F for ; Mon, 2 Aug 2021 14:47:05 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id F21EA1F42CE1 From: Gabriel Krisman Bertazi To: ltp@lists.linux.it, jack@suse.com, amir73il@gmail.com Cc: linux-ext4@vger.kernel.org, khazhy@google.com, kernel@collabora.com, Gabriel Krisman Bertazi Subject: [PATCH 2/7] syscalls/fanotify20: Validate the generic error info Date: Mon, 2 Aug 2021 17:46:40 -0400 Message-Id: <20210802214645.2633028-3-krisman@collabora.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210802214645.2633028-1-krisman@collabora.com> References: <20210802214645.2633028-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Implement some validation for the generic error info record emitted by the kernel. The error number is fs-specific but, well, we only support ext4 for now anyway. Signed-off-by: Gabriel Krisman Bertazi --- .../kernel/syscalls/fanotify/fanotify20.c | 59 ++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/testcases/kernel/syscalls/fanotify/fanotify20.c b/testcases/kernel/syscalls/fanotify/fanotify20.c index 50531bd99cc9..fd5cfb8744f1 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify20.c +++ b/testcases/kernel/syscalls/fanotify/fanotify20.c @@ -37,6 +37,14 @@ #ifndef FAN_FS_ERROR #define FAN_FS_ERROR 0x00008000 + +#define FAN_EVENT_INFO_TYPE_ERROR 4 + +struct fanotify_event_info_error { + struct fanotify_event_info_header hdr; + __s32 error; + __u32 error_count; +}; #endif #define BUF_SIZE 256 @@ -47,11 +55,54 @@ int fd_notify; static const struct test_case { char *name; + int error; + unsigned int error_count; void (*trigger_error)(void); void (*prepare_fs)(void); } testcases[] = { }; +struct fanotify_event_info_header *get_event_info( + struct fanotify_event_metadata *event, + int info_type) +{ + struct fanotify_event_info_header *hdr = NULL; + char *start = (char *) event; + int off; + + for (off = event->metadata_len; (off+sizeof(*hdr)) < event->event_len; + off += hdr->len) { + hdr = (struct fanotify_event_info_header *) &(start[off]); + if (hdr->info_type == info_type) + return hdr; + } + return NULL; +} + +#define get_event_info_error(event) \ + ((struct fanotify_event_info_error *) \ + get_event_info((event), FAN_EVENT_INFO_TYPE_ERROR)) + +int check_error_event_info_error(struct fanotify_event_info_error *info_error, + const struct test_case *ex) +{ + int fail = 0; + + if (info_error->error_count != ex->error_count) { + tst_res(TFAIL, "%s: Unexpected error_count (%d!=%d)", + ex->name, info_error->error_count, ex->error_count); + fail++; + } + + if (info_error->error != ex->error) { + tst_res(TFAIL, "%s: Unexpected error code value (%d!=%d)", + ex->name, info_error->error, ex->error); + fail++; + } + + return fail; +} + int check_error_event_metadata(struct fanotify_event_metadata *event) { int fail = 0; @@ -74,6 +125,8 @@ void check_event(char *buf, size_t len, const struct test_case *ex) { struct fanotify_event_metadata *event = (struct fanotify_event_metadata *) buf; + struct fanotify_event_info_error *info_error; + int fail = 0; if (len < FAN_EVENT_METADATA_LEN) tst_res(TFAIL, "No event metadata found"); @@ -81,7 +134,11 @@ void check_event(char *buf, size_t len, const struct test_case *ex) if (check_error_event_metadata(event)) return; - tst_res(TPASS, "Successfully received: %s", ex->name); + info_error = get_event_info_error(event); + fail += info_error ? check_error_event_info_error(info_error, ex) : 1; + + if (!fail) + tst_res(TPASS, "Successfully received: %s", ex->name); } static void do_test(unsigned int i) -- 2.32.0