From patchwork Mon Jul 1 12:35:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 1125301 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45cnBg1dcKz9s4V for ; Mon, 1 Jul 2019 22:44:43 +1000 (AEST) Received: from localhost ([::1]:58332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhvfl-0000aS-9Z for incoming@patchwork.ozlabs.org; Mon, 01 Jul 2019 08:44:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59137) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhvZi-00039X-Q5 for qemu-devel@nongnu.org; Mon, 01 Jul 2019 08:38:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hhvZf-0008U3-0M for qemu-devel@nongnu.org; Mon, 01 Jul 2019 08:38:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38920) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hhvZe-0008T5-QF for qemu-devel@nongnu.org; Mon, 01 Jul 2019 08:38:22 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F3D033086217; Mon, 1 Jul 2019 12:38:16 +0000 (UTC) Received: from localhost.localdomain (unknown [10.33.36.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B4CDC18376; Mon, 1 Jul 2019 12:38:12 +0000 (UTC) From: P J P To: Qemu Developers Date: Mon, 1 Jul 2019 18:05:56 +0530 Message-Id: <20190701123558.30512-2-ppandit@redhat.com> In-Reply-To: <20190701123558.30512-1-ppandit@redhat.com> References: <20190701123558.30512-1-ppandit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Mon, 01 Jul 2019 12:38:17 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 1/3] qemu-bridge-helper: restrict interface name to IFNAMSIZ X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riccardo Schirone , Li Qiang , Jason Wang , =?utf-8?q?Daniel_P_=2E_Berrang?= =?utf-8?b?w6k=?= , Prasad J Pandit Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Prasad J Pandit The network interface name in Linux is defined to be of size IFNAMSIZ(=16), including the terminating null('\0') byte. The same is applied to interface names read from 'bridge.conf' file to form ACL rules. If user supplied '--br=bridge' name is not restricted to the same length, it could lead to ACL bypass issue. Restrict interface name to IFNAMSIZ, including null byte. Reported-by: Riccardo Schirone Signed-off-by: Prasad J Pandit Reviewed-by: Li Qiang --- qemu-bridge-helper.c | 11 +++++++++++ 1 file changed, 11 insertions(+) Update v3: use g_str_equal() and %zu for strlen() -> https://lists.gnu.org/archive/html/qemu-devel/2019-07/msg00072.html diff --git a/qemu-bridge-helper.c b/qemu-bridge-helper.c index f9940deefd..e90c22f07d 100644 --- a/qemu-bridge-helper.c +++ b/qemu-bridge-helper.c @@ -109,6 +109,13 @@ static int parse_acl_file(const char *filename, ACLList *acl_list) } *argend = 0; + if (!g_str_equal(cmd, "include") && strlen(arg) >= IFNAMSIZ) { + fprintf(stderr, "name `%s' too long: %zu\n", arg, strlen(arg)); + fclose(f); + errno = EINVAL; + return -1; + } + if (strcmp(cmd, "deny") == 0) { acl_rule = g_malloc(sizeof(*acl_rule)); if (strcmp(arg, "all") == 0) { @@ -259,6 +266,10 @@ int main(int argc, char **argv) usage(); return EXIT_FAILURE; } + if (strlen(bridge) >= IFNAMSIZ) { + fprintf(stderr, "name `%s' too long: %zu\n", bridge, strlen(bridge)); + return EXIT_FAILURE; + } /* parse default acl file */ QSIMPLEQ_INIT(&acl_list); From patchwork Mon Jul 1 12:35:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 1125299 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45cn9W5Ctzz9s4V for ; Mon, 1 Jul 2019 22:43:43 +1000 (AEST) Received: from localhost ([::1]:58316 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhven-0006qR-QE for incoming@patchwork.ozlabs.org; Mon, 01 Jul 2019 08:43:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59257) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhvaC-0003JL-Fd for qemu-devel@nongnu.org; Mon, 01 Jul 2019 08:38:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hhva9-0000NY-3d for qemu-devel@nongnu.org; Mon, 01 Jul 2019 08:38:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60714) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hhva8-00008j-Rj for qemu-devel@nongnu.org; Mon, 01 Jul 2019 08:38:52 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6E03EC049589; Mon, 1 Jul 2019 12:38:27 +0000 (UTC) Received: from localhost.localdomain (unknown [10.33.36.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC6AD17CC0; Mon, 1 Jul 2019 12:38:18 +0000 (UTC) From: P J P To: Qemu Developers Date: Mon, 1 Jul 2019 18:05:57 +0530 Message-Id: <20190701123558.30512-3-ppandit@redhat.com> In-Reply-To: <20190701123558.30512-1-ppandit@redhat.com> References: <20190701123558.30512-1-ppandit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 01 Jul 2019 12:38:27 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 2/3] qemu-bridge-helper: move repeating code in parse_acl_file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riccardo Schirone , Li Qiang , Jason Wang , =?utf-8?q?Daniel_P_=2E_Berrang?= =?utf-8?b?w6k=?= , Prasad J Pandit Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Prasad J Pandit Move repeating error handling sequence in parse_acl_file routine to an 'err' label. Signed-off-by: Prasad J Pandit Reviewed-by: Li Qiang --- qemu-bridge-helper.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/qemu-bridge-helper.c b/qemu-bridge-helper.c index e90c22f07d..91a02f9611 100644 --- a/qemu-bridge-helper.c +++ b/qemu-bridge-helper.c @@ -92,9 +92,7 @@ static int parse_acl_file(const char *filename, ACLList *acl_list) if (arg == NULL) { fprintf(stderr, "Invalid config line:\n %s\n", line); - fclose(f); - errno = EINVAL; - return -1; + goto err; } *arg = 0; @@ -111,9 +109,7 @@ static int parse_acl_file(const char *filename, ACLList *acl_list) if (!g_str_equal(cmd, "include") && strlen(arg) >= IFNAMSIZ) { fprintf(stderr, "name `%s' too long: %zu\n", arg, strlen(arg)); - fclose(f); - errno = EINVAL; - return -1; + goto err; } if (strcmp(cmd, "deny") == 0) { @@ -139,15 +135,18 @@ static int parse_acl_file(const char *filename, ACLList *acl_list) parse_acl_file(arg, acl_list); } else { fprintf(stderr, "Unknown command `%s'\n", cmd); - fclose(f); - errno = EINVAL; - return -1; + goto err; } } fclose(f); - return 0; + +err: + fclose(f); + errno = EINVAL; + return -1; + } static bool has_vnet_hdr(int fd) From patchwork Mon Jul 1 12:35:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 1125302 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45cnCB72Mlz9sPH for ; Mon, 1 Jul 2019 22:45:10 +1000 (AEST) Received: from localhost ([::1]:58352 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhvgC-000127-JK for incoming@patchwork.ozlabs.org; Mon, 01 Jul 2019 08:45:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59260) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhvaC-0003Jy-OJ for qemu-devel@nongnu.org; Mon, 01 Jul 2019 08:38:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hhva9-0000NP-3J for qemu-devel@nongnu.org; Mon, 01 Jul 2019 08:38:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50894) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hhva8-0000BV-Ol for qemu-devel@nongnu.org; Mon, 01 Jul 2019 08:38:52 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7A0043091740; Mon, 1 Jul 2019 12:38:36 +0000 (UTC) Received: from localhost.localdomain (unknown [10.33.36.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7B9AB18376; Mon, 1 Jul 2019 12:38:29 +0000 (UTC) From: P J P To: Qemu Developers Date: Mon, 1 Jul 2019 18:05:58 +0530 Message-Id: <20190701123558.30512-4-ppandit@redhat.com> In-Reply-To: <20190701123558.30512-1-ppandit@redhat.com> References: <20190701123558.30512-1-ppandit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Mon, 01 Jul 2019 12:38:36 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 3/3] net: tap: refactor net_bridge_run_helper routine X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riccardo Schirone , Li Qiang , Jason Wang , =?utf-8?q?Daniel_P_=2E_Berrang?= =?utf-8?b?w6k=?= , Prasad J Pandit Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Prasad J Pandit Refactor 'net_bridge_run_helper' routine to avoid buffer formatting to prepare 'helper_cmd' and using shell to invoke helper command. Instead directly execute helper program with due arguments. Signed-off-by: Prasad J Pandit --- net/tap.c | 43 +++++++++---------------------------------- 1 file changed, 9 insertions(+), 34 deletions(-) Update v3: remove buffer formatting and use of shell to invoke helper -> https://lists.gnu.org/archive/html/qemu-devel/2019-07/msg00071.html diff --git a/net/tap.c b/net/tap.c index e8aadd8d4b..bc9b3407a6 100644 --- a/net/tap.c +++ b/net/tap.c @@ -478,7 +478,6 @@ static int net_bridge_run_helper(const char *helper, const char *bridge, sigset_t oldmask, mask; int pid, status; char *args[5]; - char **parg; int sv[2]; sigemptyset(&mask); @@ -498,9 +497,6 @@ static int net_bridge_run_helper(const char *helper, const char *bridge, } if (pid == 0) { int open_max = sysconf(_SC_OPEN_MAX), i; - char fd_buf[6+10]; - char br_buf[6+IFNAMSIZ] = {0}; - char helper_cmd[PATH_MAX + sizeof(fd_buf) + sizeof(br_buf) + 15]; for (i = 3; i < open_max; i++) { if (i != sv[1]) { @@ -508,39 +504,18 @@ static int net_bridge_run_helper(const char *helper, const char *bridge, } } - snprintf(fd_buf, sizeof(fd_buf), "%s%d", "--fd=", sv[1]); + args[0] = (char *)helper; + args[1] = (char *)"--use-vnet"; + args[2] = g_strdup_printf("%s%d", "--fd=", sv[1]); + args[3] = g_strdup_printf("%s%s", "--br=", bridge); + args[4] = NULL; - if (strrchr(helper, ' ') || strrchr(helper, '\t')) { - /* assume helper is a command */ + execv(helper, args); - if (strstr(helper, "--br=") == NULL) { - snprintf(br_buf, sizeof(br_buf), "%s%s", "--br=", bridge); - } + g_free(args[2]); + g_free(args[3]); + fprintf(stderr, "failed to execute helper: %s\n", helper); - snprintf(helper_cmd, sizeof(helper_cmd), "%s %s %s %s", - helper, "--use-vnet", fd_buf, br_buf); - - parg = args; - *parg++ = (char *)"sh"; - *parg++ = (char *)"-c"; - *parg++ = helper_cmd; - *parg++ = NULL; - - execv("/bin/sh", args); - } else { - /* assume helper is just the executable path name */ - - snprintf(br_buf, sizeof(br_buf), "%s%s", "--br=", bridge); - - parg = args; - *parg++ = (char *)helper; - *parg++ = (char *)"--use-vnet"; - *parg++ = fd_buf; - *parg++ = br_buf; - *parg++ = NULL; - - execv(helper, args); - } _exit(1); } else {