From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id BFEEAA328D for ; Wed, 23 Oct 2019 10:07:55 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6A8B61BFA0; Wed, 23 Oct 2019 10:07:54 +0200 (CEST) Received: from alln-iport-1.cisco.com (alln-iport-1.cisco.com [173.37.142.88]) by dpdk.org (Postfix) with ESMTP id D3A551BF91 for ; Wed, 23 Oct 2019 10:07:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=5822; q=dns/txt; s=iport; t=1571818073; x=1573027673; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=UWgCquRaliqI0ISaUFv/mw5+3OiU5UKpk4SCbPHokQE=; b=DFwPVEG78nzHf2LKhkMs2UHHN6dPzgsAnJY4mSt3FM+cuuj/Um44ZFcY elfaI3y9LK58Q3QreWqLoC8ZBn3oezEcDvKYCPHhjxWP8MMb25hOJsD8k mwrDd/C4f83hb0UFVYzHvSN/QugfX1Qdx2u5geS2sWES//toSLSS7cil2 o=; X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0AgAABTCbBd/4gNJK1lGgEBAQEBAQE?= =?us-ascii?q?BAQMBAQEBEQEBAQICAQEBAYFqAgEBAQELAYIfbFQBMSoKnxaFRYtqCQEBAQw?= =?us-ascii?q?BARsUAQGEQAKDMiQ3Bg4CAwkBAQQBAQECAQUEbYU3DIVMBidSEFFXBg4FgyI?= =?us-ascii?q?BglIlsHaBdDOFToMwgUiBNgGHNYRZGIFAP4ERg1CKMwSNCgSIRJgMgi6GLGK?= =?us-ascii?q?ODAwbgy2WIad9AhEVgWgjgVhNIxU7gmwJRxAUgxEBF4ghhgQ/AQExjn8BgSM?= =?us-ascii?q?BAQ?= X-IronPort-AV: E=Sophos;i="5.68,220,1569283200"; d="scan'208";a="348907815" Received: from alln-core-3.cisco.com ([173.36.13.136]) by alln-iport-1.cisco.com with ESMTP/TLS/DHE-RSA-SEED-SHA; 23 Oct 2019 08:07:51 +0000 Received: from XCH-ALN-004.cisco.com (xch-aln-004.cisco.com [173.36.7.14]) by alln-core-3.cisco.com (8.15.2/8.15.2) with ESMTPS id x9N87pAm027031 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=FAIL); Wed, 23 Oct 2019 08:07:51 GMT Received: from localhost.localdomain (10.61.192.224) by XCH-ALN-004.cisco.com (173.36.7.14) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 23 Oct 2019 03:07:50 -0500 From: Jakub Grajciar To: CC: Jakub Grajciar , Date: Wed, 23 Oct 2019 10:07:32 +0200 Message-ID: <20191023080732.2706-1-jgrajcia@cisco.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191022160829.21664-1-jgrajcia@cisco.com> References: <20191022160829.21664-1-jgrajcia@cisco.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.61.192.224] X-ClientProxiedBy: xch-rcd-016.cisco.com (173.37.102.26) To XCH-ALN-004.cisco.com (173.36.7.14) X-Outbound-SMTP-Client: 173.36.7.14, xch-aln-004.cisco.com X-Outbound-Node: alln-core-3.cisco.com Subject: [dpdk-dev] [PATCH v2] net/memif: fix invalid unix domain address length X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Define MEMIF_SOCKET_UN_SIZE to size of unix domain socket address. Report error in case of longer path. Fixes: b923866c6974 ("net/memif: allow for full key size in socket name") Cc: stephen@networkplumber.org Signed-off-by: Jakub Grajciar --- doc/guides/nics/memif.rst | 2 +- drivers/net/memif/memif_socket.c | 27 +++++++++++---------------- drivers/net/memif/memif_socket.h | 6 ++++-- drivers/net/memif/rte_eth_memif.c | 5 +++++ 4 files changed, 21 insertions(+), 19 deletions(-) v2: - fix coding style - fix socket path length check diff --git a/doc/guides/nics/memif.rst b/doc/guides/nics/memif.rst index de2d481eb..9a568455e 100644 --- a/doc/guides/nics/memif.rst +++ b/doc/guides/nics/memif.rst @@ -42,7 +42,7 @@ client. "role=master", "Set memif role", "slave", "master|slave" "bsize=1024", "Size of single packet buffer", "2048", "uint16_t" "rsize=11", "Log2 of ring size. If rsize is 10, actual ring size is 1024", "10", "1-14" - "socket=/tmp/memif.sock", "Socket filename", "/tmp/memif.sock", "string len 256" + "socket=/tmp/memif.sock", "Socket filename", "/tmp/memif.sock", "string len 108" "mac=01:23:45:ab:cd:ef", "Mac address", "01:ab:23:cd:45:ef", "" "secret=abc123", "Secret is an optional security option, which if specified, must be matched by peer", "", "string len 24" "zero-copy=yes", "Enable/disable zero-copy slave mode", "no", "yes|no" diff --git a/drivers/net/memif/memif_socket.c b/drivers/net/memif/memif_socket.c index 0c71f6c45..4efa68e1a 100644 --- a/drivers/net/memif/memif_socket.c +++ b/drivers/net/memif/memif_socket.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include @@ -860,16 +859,12 @@ memif_listener_handler(void *arg) rte_free(cc); } -#define MEMIF_SOCKET_UN_SIZE \ - (offsetof(struct sockaddr_un, sun_path) + MEMIF_SOCKET_KEY_LEN) - static struct memif_socket * memif_socket_create(struct pmd_internals *pmd, const char *key, uint8_t listener) { struct memif_socket *sock; - struct sockaddr_un *un; - char un_buf[MEMIF_SOCKET_UN_SIZE]; + struct sockaddr_un un; int sockfd; int ret; int on = 1; @@ -881,7 +876,7 @@ memif_socket_create(struct pmd_internals *pmd, } sock->listener = listener; - strlcpy(sock->filename, key, MEMIF_SOCKET_KEY_LEN); + strlcpy(sock->filename, key, MEMIF_SOCKET_UN_SIZE); TAILQ_INIT(&sock->dev_queue); if (listener != 0) { @@ -889,18 +884,18 @@ memif_socket_create(struct pmd_internals *pmd, if (sockfd < 0) goto error; - memset(un_buf, 0, sizeof(un_buf)); - un = (struct sockaddr_un *)un_buf; - un->sun_family = AF_UNIX; - strlcpy(un->sun_path, sock->filename, MEMIF_SOCKET_KEY_LEN); + un.sun_family = AF_UNIX; + strlcpy(un.sun_path, sock->filename, MEMIF_SOCKET_UN_SIZE); ret = setsockopt(sockfd, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)); if (ret < 0) goto error; - ret = bind(sockfd, (struct sockaddr *)un, MEMIF_SOCKET_UN_SIZE); + + ret = bind(sockfd, (struct sockaddr *)&un, sizeof(un)); if (ret < 0) goto error; + ret = listen(sockfd, 1); if (ret < 0) goto error; @@ -940,7 +935,7 @@ memif_create_socket_hash(void) params.name = MEMIF_SOCKET_HASH_NAME; params.entries = 256; - params.key_len = MEMIF_SOCKET_KEY_LEN; + params.key_len = MEMIF_SOCKET_UN_SIZE; params.hash_func = rte_jhash; params.hash_func_init_val = 0; return rte_hash_create(¶ms); @@ -955,7 +950,7 @@ memif_socket_init(struct rte_eth_dev *dev, const char *socket_filename) struct pmd_internals *tmp_pmd; struct rte_hash *hash; int ret; - char key[MEMIF_SOCKET_KEY_LEN]; + char key[MEMIF_SOCKET_UN_SIZE]; hash = rte_hash_find_existing(MEMIF_SOCKET_HASH_NAME); if (hash == NULL) { @@ -966,8 +961,8 @@ memif_socket_init(struct rte_eth_dev *dev, const char *socket_filename) } } - memset(key, 0, MEMIF_SOCKET_KEY_LEN); - strlcpy(key, socket_filename, MEMIF_SOCKET_KEY_LEN); + memset(key, 0, MEMIF_SOCKET_UN_SIZE); + strlcpy(key, socket_filename, MEMIF_SOCKET_UN_SIZE); ret = rte_hash_lookup_data(hash, key, (void **)&socket); if (ret < 0) { socket = memif_socket_create(pmd, key, diff --git a/drivers/net/memif/memif_socket.h b/drivers/net/memif/memif_socket.h index 9f40f8d13..5c49ec24e 100644 --- a/drivers/net/memif/memif_socket.h +++ b/drivers/net/memif/memif_socket.h @@ -6,6 +6,7 @@ #define _MEMIF_SOCKET_H_ #include +#include /** * Remove device from socket device list. If no device is left on the socket, @@ -79,11 +80,12 @@ struct memif_socket_dev_list_elt { }; #define MEMIF_SOCKET_HASH_NAME "memif-sh" -#define MEMIF_SOCKET_KEY_LEN 256 +#define MEMIF_SOCKET_UN_SIZE \ + (sizeof(struct sockaddr_un) - offsetof(struct sockaddr_un, sun_path)) struct memif_socket { struct rte_intr_handle intr_handle; /**< interrupt handle */ - char filename[MEMIF_SOCKET_KEY_LEN]; /**< socket filename */ + char filename[MEMIF_SOCKET_UN_SIZE]; /**< socket filename */ TAILQ_HEAD(, memif_socket_dev_list_elt) dev_queue; /**< Queue of devices using this socket */ diff --git a/drivers/net/memif/rte_eth_memif.c b/drivers/net/memif/rte_eth_memif.c index a347e27bd..d52db91ed 100644 --- a/drivers/net/memif/rte_eth_memif.c +++ b/drivers/net/memif/rte_eth_memif.c @@ -1192,6 +1192,11 @@ memif_check_socket_filename(const char *filename) uint32_t idx; int ret = 0; + if (strlen(filename) >= MEMIF_SOCKET_UN_SIZE) { + MIF_LOG(ERR, "Unix socket address too long (max 108)."); + return -1; + } + tmp = strrchr(filename, '/'); if (tmp != NULL) { idx = tmp - filename; -- 2.17.1