Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1948680pxy; Mon, 2 Aug 2021 14:47:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyHYHS2A+zM3l2x+4Ct2Eh297w4iNEqGcRqARVwIumi90GMsopvwMB6PM8k2GXFgEAC7pR X-Received: by 2002:a02:ba87:: with SMTP id g7mr10076530jao.110.1627940846276; Mon, 02 Aug 2021 14:47:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627940846; cv=none; d=google.com; s=arc-20160816; b=gOSFU2gUAXjFRuiHdgxKeeniA8et3h9QEYevqfwE+FKtAobqMfPxL8U49LYJCbJGP0 D3woVO2WvlIxdgM1WRELyzrZoIttNkOg+ROgLP23+n3OOBoV3BrklMGs2S5BJBezJ/jx 4uBE3+KiPCdG5FtXY+03rt0aQAL5Z9ECQCKcoHrWevWp7sKHRdjlqHK0Sz6KkqpJytQp H+n2wN1Mag1lMnHq6jDIHhYI3EQtQO/3uvm8Ky9eVOe5777AmIvfpwakNY/OOqv2Y3Q1 xQrG76zvDlYVYXI2uesUoyGm+ohf3LwmjkKZC3c3Yek9Qql43kWFnG+285PfxCS4qiPy yNaQ== 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; bh=cNULTPz8AwSzgf8Y3rOSpvkFC7sKbSGSbCeceOipmkw=; b=Gw9tLSGNfGlj4qIV1OIzbvIDtYn2HTlxO9bBtItV/84ZzBhieyQOxxLYLA2oSkDwlG lfgEmqD4JONQ+bCRepBnYCv4YVBOh7uwOXDCyr5lCof6JkI2ljjvkA3SS70rLuAJFnPW 16Ec/TZHa84ofPd2V7PKtb9eo7Lx3VAmTA0CPb3mqs0gljKlT8CQDRKF7+mDAARqeGZM krZTLFg40x2lZH7rE1sFPogv0f8UwD7F9uy1HRKQiWEypZidoAku6bMwgfT0uLdIRqy8 uRLArb9PKyVpzwx/yu3CLF1RY7U61ziR7Mt86fcpj+aactEzhOPv39FRA9FN2brNcwEN to0g== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v66si6440505iof.105.2021.08.02.14.47.14; Mon, 02 Aug 2021 14:47:26 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231651AbhHBVrP (ORCPT + 99 others); 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