Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1948776pxy; Mon, 2 Aug 2021 14:47:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKsqxDAPJ4puZ0P+GCZlixXInFFCPYoGtXqC5X9XfHSOjBo8JmTdVL2FOeJfU+rUBZq/1M X-Received: by 2002:a6b:8f8f:: with SMTP id r137mr1988617iod.185.1627940856949; Mon, 02 Aug 2021 14:47:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627940856; cv=none; d=google.com; s=arc-20160816; b=ddeP+8Ki7eM71pr1uARKCffE9V8FZvkjEwOLQJJP5+86IQa1fKqJBe6kgF5ocjmQz+ YPeeL7zbDSZVBxgNKlcN0sRUnobyDFgXEDzg/ykwhtiBkDv5fVzNfQnSzOaFJE0VvLc2 3IsGHQiWp/kho1fPqGhtTPBY9wmF56MtzjibZi4dnw5sv+3E0WGOgBU/Hq176vGX5IE+ zibDVvHMoXifCo73uZa1khz1wM4QekhTlq3UsTcL46Vyzsm6ih2Ea0kWP00P1st2gcna ZKj9x7xLbmSge7ctxlMgGfwuwvulKPsBFQtl726V6ZXnahC/pYyMau50cGERkcAus67d VIJg== 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=HbpcOGJR3ncQOO+EqLqOUuVYCgWzSIhyWSM9UrXLKzg=; b=wUOr86jLv2DPq+HfNm5d3DVKGXmMSBMoatnJtCBbr8XxoedlIOzChaNa8Z/HtbpvrS XfiLn3d98V6ANuHUaud7yEkH+kRRnc6C+5W2Io025P95syywF7y+hDlnWSnuM1zmSFFP BxIlYBDvlHu93/vPLZDrDsykSYSY23QQADXBccntJbsxu/dsPHEsFwq/QqoOajN893Pe DmFlajO6sXveTL2Nr/0LdKGnuNzG9QVXjEA6ZnXEpVfzWPGLypKcc+vDN8SDQVvLNfVM tnjfeZr8Xq6EooOgwVjtxfq/AOc6h5rMyoe/aKzbKgbPssDF2dYvatwsZiu8JgdafJ3n vUPA== 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 b15si13725723ioj.7.2021.08.02.14.47.25; Mon, 02 Aug 2021 14:47:36 -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 S231720AbhHBVrT (ORCPT + 99 others); Mon, 2 Aug 2021 17:47:19 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:38216 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229567AbhHBVrT (ORCPT ); Mon, 2 Aug 2021 17:47:19 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 556101F42CE9 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 3/7] syscalls/fanotify20: Validate incoming FID in FAN_FS_ERROR Date: Mon, 2 Aug 2021 17:46:41 -0400 Message-Id: <20210802214645.2633028-4-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 Verify the FID provided in the event. If the testcase has a null inode, this is assumed to be a superblock error (i.e. null FH). Signed-off-by: Gabriel Krisman Bertazi --- .../kernel/syscalls/fanotify/fanotify20.c | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/testcases/kernel/syscalls/fanotify/fanotify20.c b/testcases/kernel/syscalls/fanotify/fanotify20.c index fd5cfb8744f1..d8d788ae685f 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify20.c +++ b/testcases/kernel/syscalls/fanotify/fanotify20.c @@ -40,6 +40,14 @@ #define FAN_EVENT_INFO_TYPE_ERROR 4 +#ifndef FILEID_INVALID +#define FILEID_INVALID 0xff +#endif + +#ifndef FILEID_INO32_GEN +#define FILEID_INO32_GEN 1 +#endif + struct fanotify_event_info_error { struct fanotify_event_info_header hdr; __s32 error; @@ -57,6 +65,9 @@ static const struct test_case { char *name; int error; unsigned int error_count; + + /* inode can be null for superblock errors */ + unsigned int *inode; void (*trigger_error)(void); void (*prepare_fs)(void); } testcases[] = { @@ -83,6 +94,42 @@ struct fanotify_event_info_header *get_event_info( ((struct fanotify_event_info_error *) \ get_event_info((event), FAN_EVENT_INFO_TYPE_ERROR)) +#define get_event_info_fid(event) \ + ((struct fanotify_event_info_fid *) \ + get_event_info((event), FAN_EVENT_INFO_TYPE_FID)) + +int check_error_event_info_fid(struct fanotify_event_info_fid *fid, + const struct test_case *ex) +{ + int fail = 0; + struct file_handle *fh = (struct file_handle *) &fid->handle; + + if (!ex->inode) { + uint32_t *h = (uint32_t *) fh->f_handle; + + if (!(fh->handle_type == FILEID_INVALID && !h[0] && !h[1])) { + tst_res(TFAIL, "%s: file handle should have been invalid", + ex->name); + fail++; + } + return fail; + } else if (fh->handle_type == FILEID_INO32_GEN) { + uint32_t *h = (uint32_t *) fh->f_handle; + + if (h[0] != *ex->inode) { + tst_res(TFAIL, + "%s: Unexpected file handle inode (%u!=%u)", + ex->name, *ex->inode, h[0]); + fail++; + } + } else { + tst_res(TFAIL, "%s: Test can't handle received FH type (%d)", + ex->name, fh->handle_type); + } + + return fail; +} + int check_error_event_info_error(struct fanotify_event_info_error *info_error, const struct test_case *ex) { @@ -126,6 +173,7 @@ 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; + struct fanotify_event_info_fid *info_fid; int fail = 0; if (len < FAN_EVENT_METADATA_LEN) @@ -137,6 +185,9 @@ void check_event(char *buf, size_t len, const struct test_case *ex) info_error = get_event_info_error(event); fail += info_error ? check_error_event_info_error(info_error, ex) : 1; + info_fid = get_event_info_fid(event); + fail += info_fid ? check_error_event_info_fid(info_fid, ex) : 1; + if (!fail) tst_res(TPASS, "Successfully received: %s", ex->name); } -- 2.32.0