Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp266846pxv; Wed, 30 Jun 2021 05:18:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypEQW7AkC3QKEKhitm6u1UNDhfBTTJw02DchGWu4eklFUxbWH+T85S1reI8msxAKqS5teT X-Received: by 2002:a17:906:b6c5:: with SMTP id ec5mr34547405ejb.290.1625055532425; Wed, 30 Jun 2021 05:18:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625055532; cv=none; d=google.com; s=arc-20160816; b=bDyhDOqEd9DBuV6TJLxpgJUV8PO7JglZk+gAWky6oXw25Y5QMIh8Alq3zd/+SKo9AE ARQgWMPf/hyu9wvms67BeKjyf5tP1pKfbN64OR3bt7MrcBX1RjVusaF12NSh6gMXuyJ+ PRtzX8L6XcWRg8Uq2pnnjuhr7+svHQAp96V++5pjbujcIrb048UuMQLZEkOZu+FCZJcT sZcUa2SDFp0tw+rXMS3hbTa0B89mqHa0uzrrvfjgvgSKT5IMoxqGw3bdnG6Sv0PteOR2 p+yWZokwxhk9tejEpo+Hu3XdQlkcxqrxCEWrU9m21PhAS6iT6BdV1ene+Q3TSkiARcjn IzHw== 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; bh=S5U28ywwLl6OV7xmavpG2YSBQN6F4k443zEP4QDb3fA=; b=QUniiCIc6+8mbkL8CiDttd/JEnMzNpP/oVj9lbxE7sCaoc0kRhHcDlhRM7QhADysEo LhUE25/e3gaGVjELO0NuThy1x4UBzt1P0l++D+zIHQyVSBw+qcvPNGXW7WYmsVzL6OWZ jx6JX8BCfXEgslfFXghhZNp1imw4uZ7Ymb4RF9Q2lIe0aC+6Asr5ijQBY2RF3lUT3FFi EaPnzfMztRU/xYlvggce43Xv+l9SJLbNgkEFKtlNBtCGQE4k/0HsXUv3OCW5LLOCuFO3 EgzvBFA9eXdwxq6L/gT2rz23ABYUlBiw4AR8XlHgZSh1H9MQzpy5/cakeIMwquvDYtVG 8aVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IP4a7e9b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m7si20268479edq.86.2021.06.30.05.18.28; Wed, 30 Jun 2021 05:18:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IP4a7e9b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S234444AbhF3MTg (ORCPT + 99 others); Wed, 30 Jun 2021 08:19:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57877 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234376AbhF3MTf (ORCPT ); Wed, 30 Jun 2021 08:19:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625055426; 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: in-reply-to:in-reply-to:references:references; bh=S5U28ywwLl6OV7xmavpG2YSBQN6F4k443zEP4QDb3fA=; b=IP4a7e9bTjPvR6WU7Mug5ASpSC7cwlIWdndPPRRwwkPKhDcLnex6SqryAYAYhO39dSDku6 LkXPBHmGMgAcQRXCWnz8tQAG7TdMgyGj+WzrYPVMANWOtd+ZWNNuMWm22m2YrL5Zs7/Ob6 gTwDIyUr68aREdACRxuPWwsx9KmJK0E= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-591-3lkCWl_RObGDksLghg8iMg-1; Wed, 30 Jun 2021 08:17:04 -0400 X-MC-Unique: 3lkCWl_RObGDksLghg8iMg-1 Received: by mail-ej1-f69.google.com with SMTP id f1-20020a1709064941b02903f6b5ef17bfso676419ejt.20 for ; Wed, 30 Jun 2021 05:17:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=S5U28ywwLl6OV7xmavpG2YSBQN6F4k443zEP4QDb3fA=; b=Zws+qkTS4zVT/gwni/DGvdbaYRpMZWwRIYYqNCnlLTjVNDZRAyPvRE2JEYDhym6d9w BYMslqylTXmCq9t/Ij1kP8WBz/EEdKmGu1Pg4/inbO5+YjIBagx3XsUBujWLIxqX919Y wNmBMpocCopmIZvnRi0IvG76Gfws7zxsOzto6zMysRiLf5JJmJR85l31sKyn8lRDjxAH 7vwDrjqpfQeUEhAisVnYhZpmUXsvn6okP5EanaFuyhuz0p8VEK0uumtRIT7QL43obKci ud9aXtfEGYOGXpItS/KBxste0W5O9lk7v1mPw/8O8uFdymyoZ/PisUhJH8/E9t+6GuPj iykw== X-Gm-Message-State: AOAM532IkVo7j/zVimvsfc32TWcmOVwQqsZ9aDZD8M9pahYJ40ZXVNms 8XTOyxQRfdg6IGmhfXxcdnZF8rP0ldSky6A3omwHaJ+OFeWW5s0PXu/lwx2NyfQEpoyQKPZ7sWI 1Oz5SAQ8S2166nJD6Zdxgyc+u X-Received: by 2002:aa7:cb43:: with SMTP id w3mr47972946edt.126.1625055423545; Wed, 30 Jun 2021 05:17:03 -0700 (PDT) X-Received: by 2002:aa7:cb43:: with SMTP id w3mr47972923edt.126.1625055423383; Wed, 30 Jun 2021 05:17:03 -0700 (PDT) Received: from steredhat (host-79-18-148-79.retail.telecomitalia.it. [79.18.148.79]) by smtp.gmail.com with ESMTPSA id v24sm799726eds.39.2021.06.30.05.17.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 05:17:03 -0700 (PDT) Date: Wed, 30 Jun 2021 14:17:00 +0200 From: Stefano Garzarella To: Arseny Krasnov Cc: Stefan Hajnoczi , "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Jakub Kicinski , Jorgen Hansen , Norbert Slusarek , Colin Ian King , Andra Paraschiv , kvm , Linux Virtualization , netdev , kernel list , Krasnov Arseniy Subject: Re: [RFC PATCH v1 16/16] vsock_test: SEQPACKET read to broken buffer Message-ID: References: <20210628095959.569772-1-arseny.krasnov@kaspersky.com> <20210628100539.572000-1-arseny.krasnov@kaspersky.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210628100539.572000-1-arseny.krasnov@kaspersky.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 28, 2021 at 01:05:36PM +0300, Arseny Krasnov wrote: >Add test where sender sends two message, each with own >data pattern. Reader tries to read first to broken buffer: >it has three pages size, but middle page is unmapped. Then, >reader tries to read second message to valid buffer. Test >checks, that uncopied part of first message was dropped >and thus not copied as part of second message. > >Signed-off-by: Arseny Krasnov >--- > tools/testing/vsock/vsock_test.c | 121 +++++++++++++++++++++++++++++++ > 1 file changed, 121 insertions(+) Cool test! Thanks for doing this! > >diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c >index 67766bfe176f..697ba168e97f 100644 >--- a/tools/testing/vsock/vsock_test.c >+++ b/tools/testing/vsock/vsock_test.c >@@ -16,6 +16,7 @@ > #include > #include > #include >+#include > > #include "timeout.h" > #include "control.h" >@@ -385,6 +386,121 @@ static void test_seqpacket_msg_trunc_server(const struct test_opts *opts) > close(fd); > } > >+#define BUF_PATTERN_1 'a' >+#define BUF_PATTERN_2 'b' >+ >+static void test_seqpacket_invalid_rec_buffer_client(const struct test_opts *opts) >+{ >+ int fd; >+ unsigned char *buf1; >+ unsigned char *buf2; >+ int buf_size = getpagesize() * 3; >+ >+ fd = vsock_seqpacket_connect(opts->peer_cid, 1234); >+ if (fd < 0) { >+ perror("connect"); >+ exit(EXIT_FAILURE); >+ } >+ >+ buf1 = malloc(buf_size); >+ if (buf1 == NULL) { checkpatch suggests to use "if (!buf1)" ... >+ perror("'malloc()' for 'buf1'"); >+ exit(EXIT_FAILURE); >+ } >+ >+ buf2 = malloc(buf_size); >+ if (buf2 == NULL) { ... and "if (!buf2)" ... >+ perror("'malloc()' for 'buf2'"); >+ exit(EXIT_FAILURE); >+ } >+ >+ memset(buf1, BUF_PATTERN_1, buf_size); >+ memset(buf2, BUF_PATTERN_2, buf_size); >+ >+ if (send(fd, buf1, buf_size, 0) != buf_size) { >+ perror("send failed"); >+ exit(EXIT_FAILURE); >+ } >+ >+ if (send(fd, buf2, buf_size, 0) != buf_size) { >+ perror("send failed"); >+ exit(EXIT_FAILURE); >+ } >+ >+ close(fd); >+} >+ >+static void test_seqpacket_invalid_rec_buffer_server(const struct test_opts *opts) >+{ >+ int fd; >+ unsigned char *broken_buf; >+ unsigned char *valid_buf; >+ int page_size = getpagesize(); >+ int buf_size = page_size * 3; >+ ssize_t res; >+ int prot = PROT_READ | PROT_WRITE; >+ int flags = MAP_PRIVATE | MAP_ANONYMOUS; >+ int i; >+ >+ fd = vsock_seqpacket_accept(VMADDR_CID_ANY, 1234, NULL); >+ if (fd < 0) { >+ perror("accept"); >+ exit(EXIT_FAILURE); >+ } >+ >+ /* Setup first buffer. */ >+ broken_buf = mmap(NULL, buf_size, prot, flags, -1, 0); >+ if (broken_buf == MAP_FAILED) { >+ perror("mmap for 'broken_buf'"); >+ exit(EXIT_FAILURE); >+ } >+ >+ /* Unmap "hole" in buffer. */ >+ if (munmap(broken_buf + page_size, page_size)) { >+ perror("'broken_buf' setup"); >+ exit(EXIT_FAILURE); >+ } >+ >+ valid_buf = mmap(NULL, buf_size, prot, flags, -1, 0); >+ if (valid_buf == MAP_FAILED) { >+ perror("mmap for 'valid_buf'"); >+ exit(EXIT_FAILURE); >+ } >+ >+ /* Try to fill buffer with unmapped middle. */ >+ res = read(fd, broken_buf, buf_size); >+ if (res != -1) { >+ perror("invalid read result of 'broken_buf'"); >+ exit(EXIT_FAILURE); >+ } >+ >+ if (errno != ENOMEM) { >+ perror("invalid errno of 'broken_buf'"); >+ exit(EXIT_FAILURE); >+ } >+ >+ /* Try to fill valid buffer. */ >+ res = read(fd, valid_buf, buf_size); >+ if (res != buf_size) { >+ perror("invalid read result of 'valid_buf'"); >+ exit(EXIT_FAILURE); >+ } >+ >+ for (i = 0; i < buf_size; i++) { >+ if (valid_buf[i] != BUF_PATTERN_2) { >+ perror("invalid pattern for valid buf"); >+ exit(EXIT_FAILURE); >+ } >+ } >+ >+ ... and to remove the extra blank line here :-) Thanks, Stefano >+ /* Unmap buffers. */ >+ munmap(broken_buf, page_size); >+ munmap(broken_buf + page_size * 2, page_size); >+ munmap(valid_buf, buf_size); >+ close(fd); >+} >+ > static struct test_case test_cases[] = { > { > .name = "SOCK_STREAM connection reset", >@@ -425,6 +541,11 @@ static struct test_case test_cases[] = { > .run_client = test_seqpacket_msg_trunc_client, > .run_server = test_seqpacket_msg_trunc_server, > }, >+ { >+ .name = "SOCK_SEQPACKET invalid receive buffer", >+ .run_client = test_seqpacket_invalid_rec_buffer_client, >+ .run_server = test_seqpacket_invalid_rec_buffer_server, >+ }, > {}, > }; > >-- >2.25.1 >