From patchwork Thu Jan 24 14:13:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gal Pressman X-Patchwork-Id: 10779089 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7F2FC13B5 for ; Thu, 24 Jan 2019 14:14:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68CBA300CF for ; Thu, 24 Jan 2019 14:14:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62149300FE; Thu, 24 Jan 2019 14:14:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA47D300E9 for ; Thu, 24 Jan 2019 14:14:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727694AbfAXOOA (ORCPT ); Thu, 24 Jan 2019 09:14:00 -0500 Received: from smtp-fw-2101.amazon.com ([72.21.196.25]:48540 "EHLO smtp-fw-2101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727562AbfAXOOA (ORCPT ); Thu, 24 Jan 2019 09:14:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1548339239; x=1579875239; h=from:to:cc:subject:date:message-id:mime-version; bh=hsAx4AAoHPOc03J7QHzNPVDw2+OvENvbaJsZKCJWUO8=; b=KnrqbjiLbsU3yXkqmBjocAA9ACpNRqoNb/KIH+SlIfJULqEB0e3W0eVP 5ldWnacHPl1obwkF72x5yTKJCBIj1+zD3EjbzEcGrbXjFU7zuiyAypuMY klxo/WyJEQCxPyoXWsV1r5uZ5dxtItHAiQvHlFmBHq6qtlyh381EbWdpy 0=; X-IronPort-AV: E=Sophos;i="5.56,516,1539648000"; d="scan'208";a="714559889" Received: from iad6-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2a-6e2fc477.us-west-2.amazon.com) ([10.124.125.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 24 Jan 2019 14:13:58 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-2a-6e2fc477.us-west-2.amazon.com (Postfix) with ESMTPS id 759E6A2343; Thu, 24 Jan 2019 14:13:57 +0000 (UTC) Received: from EX13D13EUA003.ant.amazon.com (10.43.165.25) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 24 Jan 2019 14:13:56 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D13EUA003.ant.amazon.com (10.43.165.25) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 24 Jan 2019 14:13:55 +0000 Received: from galpress-VirtualBox.hfa16.amazon.com (10.218.62.29) by mail-relay.amazon.com (10.43.60.129) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Thu, 24 Jan 2019 14:13:52 +0000 From: Gal Pressman To: Yishai Hadas , Jason Gunthorpe , Doug Ledford , Leon Romanovsky CC: , Yossi Leybovich , "Gal Pressman" , Yuval Shaia Subject: [PATCH rdma-core v2] verbs: Fix UD pingpong buffer validation Date: Thu, 24 Jan 2019 16:13:48 +0200 Message-ID: <1548339228-3824-1-git-send-email-galpress@amazon.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The buffer allocated in the test has extra 40 bytes reserved for GRH for both the client and the server, while the actual payload starts at offset 40. Since the buffer validation applies to the payload only, we should take this offset into account: As the sender, make sure to fill the payload starting at offset 40 as all data before that will not be sent on ibv_post_send. As the receiver, make sure to validate the payload starting at offset 40 as all data before that is not part of the actual payload (GRH/not valid). Also, The buffer validation option doesn't require an extra parameter, remove the extra ':'. Fixes: 099c5aa50bc8 ("libibverb/examples: Add command line option to enable buffer validation") Cc: Yuval Shaia Signed-off-by: Gal Pressman Reviewed-by: Yishai Hadas --- Changelog: v1->v2 * Make the commit message more clear * Resolve the getopt issue --- libibverbs/examples/ud_pingpong.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libibverbs/examples/ud_pingpong.c b/libibverbs/examples/ud_pingpong.c index a89fbe3148ad..0e1a481b9530 100644 --- a/libibverbs/examples/ud_pingpong.c +++ b/libibverbs/examples/ud_pingpong.c @@ -593,7 +593,7 @@ int main(int argc, char *argv[]) {} }; - c = getopt_long(argc, argv, "p:d:i:s:r:n:l:eg:c:", long_options, + c = getopt_long(argc, argv, "p:d:i:s:r:n:l:eg:c", long_options, NULL); if (c == -1) break; @@ -747,7 +747,7 @@ int main(int argc, char *argv[]) if (servername) { if (validate_buf) for (int i = 0; i < size; i += page_size) - ctx->buf[i] = i / page_size % sizeof(char); + ctx->buf[i + 40] = i / page_size % sizeof(char); if (pp_post_send(ctx, rem_dest->qpn)) { fprintf(stderr, "Couldn't post send\n"); @@ -860,7 +860,8 @@ int main(int argc, char *argv[]) if ((!servername) && (validate_buf)) { for (int i = 0; i < size; i += page_size) - if (ctx->buf[i] != i / page_size % sizeof(char)) + if (ctx->buf[i + 40] != + i / page_size % sizeof(char)) printf("invalid data in page %d\n", i / page_size); }