From patchwork Mon Jan 11 14:16:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 565899 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1D9B61402ED for ; Tue, 12 Jan 2016 01:24:42 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b=LKY43wp1; dkim-atps=neutral Received: from localhost ([::1]:54537 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIdOh-0002oE-RB for incoming@patchwork.ozlabs.org; Mon, 11 Jan 2016 09:24:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52569) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIdGr-0004Xt-NN for qemu-devel@nongnu.org; Mon, 11 Jan 2016 09:16:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aIdGn-00028c-3w for qemu-devel@nongnu.org; Mon, 11 Jan 2016 09:16:33 -0500 Received: from mail-lf0-x22e.google.com ([2a00:1450:4010:c07::22e]:34160) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIdGm-00028O-Sj for qemu-devel@nongnu.org; Mon, 11 Jan 2016 09:16:29 -0500 Received: by mail-lf0-x22e.google.com with SMTP id 17so11990638lfz.1 for ; Mon, 11 Jan 2016 06:16:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ScL6lKV62gHftn/0jDy7RMiJCPWgk5vErHrTSZCnlVs=; b=LKY43wp1QBRn5RpcTpVUlXcAtbXKqDPqJ8FcBrTi3PiZLfwAm4n/sNzJf89lUjZuCh bXSg+8ZuHNP350wkh2ed4RQ3HmLkvEZ77kkGJKdJxFES3cYRc4VzCjIF0LAgPLUlNfWj Y0Afl+tjNYVqtk6+kUdNacUf99JsrHkPFC8mE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ScL6lKV62gHftn/0jDy7RMiJCPWgk5vErHrTSZCnlVs=; b=V+bVg87ECrjtOYrgNie4NAUG7u36B1ClDPskxIysJbN14RL2z3ZAwM7L6UEHCA2e3Y hYND69+Z99A6uOknsCxtoy9IUoS0KtsPnCWOflD1RJd1zNblnY2/qPQfAbcb36tEEfD7 /Iq4hLjZjZi7P1MsNb+yNVjHyzQvwdTT2T4ZDlgdGslmdQtyM1WRgu7XTOTx/nXdhUpr 1Qrz2aZ5vHLXdykXwy863toqJJGMLCZMT26dd9235NDAtLQVs3YVJ7dS+5zDX1F3hY0M SRoRiCXL76Oc84HVWilFTTpeKAIErl7wXbZHRutq3S6SSXryLt92Wn0vGNECXuW01nz3 fXPg== X-Gm-Message-State: ALoCoQmtoGdlPP4FaiTYscDcbXTkdAY9GiiBV83iINzOMzDF+aQ6KXdPeQySGYz0o2Z1qSv7++pf8pMEgozKnMO7Z6B2zjSj0g== X-Received: by 10.25.28.80 with SMTP id c77mr45378953lfc.74.1452521788260; Mon, 11 Jan 2016 06:16:28 -0800 (PST) Received: from localhost.localdomain (91-157-175-207.elisa-laajakaista.fi. [91.157.175.207]) by smtp.gmail.com with ESMTPSA id 130sm16806735lff.31.2016.01.11.06.16.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 Jan 2016 06:16:27 -0800 (PST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Mon, 11 Jan 2016 16:16:07 +0200 Message-Id: X-Mailer: git-send-email 2.6.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::22e Cc: Laurent Vivier Subject: [Qemu-devel] [PULL 05/17] linux-user: SOCK_PACKET uses network endian to encode protocol in socket() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Laurent Vivier in PACKET(7) : packet_socket = socket(AF_PACKET, int socket_type, int protocol); [...] protocol is the IEEE 802.3 protocol number in network order. See the include file for a list of allowed protocols. When protocol is set to htons(ETH_P_ALL) then all protocols are received. All incoming packets of that protocol type will be passed to the packet socket before they are passed to the protocols implemented in the kernel. [...] Compatibility In Linux 2.0, the only way to get a packet socket was by calling socket(AF_INET, SOCK_PACKET, protocol). We need to tswap16() the protocol because on big-endian, the ABI is waiting for, for instance for ETH_P_ALL, 0x0003 (big endian == network order), whereas on little-endian it is waiting for 0x0300. Signed-off-by: Laurent Vivier Reviewed-by: Peter Maydell Signed-off-by: Riku Voipio --- linux-user/syscall.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 06a59b4..965d7db 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -2089,6 +2089,12 @@ static abi_long do_socket(int domain, int type, int protocol) if (domain == PF_NETLINK) return -TARGET_EAFNOSUPPORT; + + if (domain == AF_PACKET || + (domain == AF_INET && type == SOCK_PACKET)) { + protocol = tswap16(protocol); + } + ret = get_errno(socket(domain, type, protocol)); if (ret >= 0) { ret = sock_flags_fixup(ret, target_type);