From patchwork Tue May 10 09:55:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Danzberger X-Patchwork-Id: 1629062 X-Patchwork-Delegate: hauke@hauke-m.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=oEtz96XF; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=dd-wrt.com header.i=@dd-wrt.com header.a=rsa-sha256 header.s=mikd header.b=dwg8417D; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KyD5935W4z9s2R for ; Tue, 10 May 2022 19:58:37 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:Message-Id:Date:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=b9PxbEU62rrdK2m6Jq57Uob1tlk9fyhHLmEjZRur3vQ=; b=oEtz96XFZtqRWz IUItslNyBeG5IVV8mXBESk5eOlzTH/WnCsHUsc0SHKlYKxU4d2u40LKI0umTkCQJobKwMMFkHVL5N 8hTVQnQhhRbSEshuvG6BxcQVY8o5HUr/ROuVUomTDdYz6T5Wg/ISrxk9rTErYMrz9FXBYzCsSkysP i9fFCyHF896VUQXUk0calkhUc98mtSCcuDFB/NKVRrL9MsgEjsMzMP84n33QEPB/usHsUAOC2cedS 0E/O2pWf/EujD0BOjyd9ej2OE445DeRW2K+cksQZ0sjcmWqdvyqeIOCwo9qJr+IFjYDVpWp3H5kSE y9WmE+EUJJBZvHqm2nMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1noMbN-0010UF-G4; Tue, 10 May 2022 09:56:21 +0000 Received: from smtps.newmedia-net.de ([2a05:a1c0:0:de::167] helo=webmail.newmedia-net.de) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1noMbI-0010Pn-Rt for openwrt-devel@lists.openwrt.org; Tue, 10 May 2022 09:56:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=dd-wrt.com; s=mikd; h=Subject:Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Cc:To:From; bh=ujn06+NOZd3GZIPRn7Xv+25tcjBEnXCP0PZaCroItM8=; b=dwg8417Dr8+3NlVIcQk7UH1qUc1o6ioHn9Cf5LmqtoYju69+QcyAMgy8xA5M4UWTuuY9/fA2+x23QEWKfCQIiJlXAOjUTd4ycrIqPQ6Zj3R8CQynpFNkjeywlVhjDVFCIXYK8YjcR7AhgEQPEc+65ly1O/sSDg127aHtD7s5Jok=; From: Daniel Danzberger To: openwrt-devel@lists.openwrt.org Cc: john@phrozen.org, Daniel Danzberger Date: Tue, 10 May 2022 11:55:53 +0200 Message-Id: <20220510095553.4056033-1-daniel@dd-wrt.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a05:a1c7:1:b101:9ba7:5add:4581:a0b5 X-SA-Exim-Mail-From: daniel@dd-wrt.com Subject: [PATCH] umbim: fix invalid mbim message string encoding X-SA-Exim-Version: 4.2.1 (built Thu, 26 May 2011 15:22:33 +0200) X-SA-Exim-Scanned: No (on webmail.newmedia-net.de); Unknown failure X-NMN-MailScanner-Information: Please contact the ISP for more information X-NMN-MailScanner-ID: 1noMb4-000AW0-8b X-NMN-MailScanner: Found to be clean X-NMN-MailScanner-From: daniel@dd-wrt.com X-Spam-Status: No X-Received: from [2a05:a1c7:1:b101:9ba7:5add:4581:a0b5] (helo=lappi.newmedia-net.de) by webmail.newmedia-net.de with esmtpa (Exim 4.72) (envelope-from ) id 1noMb4-000AW0-8b; Tue, 10 May 2022 11:56:05 +0200 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220510_025617_240186_D79E9E2B X-CRM114-Status: UNSURE ( 9.45 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Strings in mbim messages have to follow these formatting rules: - 4 byte alignment, padded if not. - utf-16 little endian. Fixes: - mbim connect fails with more than 1 string parameter (apn/user/pass) when they are not 4 byte aligned. Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Strings in mbim messages have to follow these formatting rules: - 4 byte alignment, padded if not. - utf-16 little endian. Fixes: - mbim connect fails with more than 1 string parameter (apn/user/pass) when they are not 4 byte aligned. Signed-off-by: Daniel Danzberger --- mbim-msg.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mbim-msg.c b/mbim-msg.c index 5ec04f4..8465091 100644 --- a/mbim-msg.c +++ b/mbim-msg.c @@ -53,8 +53,10 @@ mbim_add_payload(uint8_t len) int mbim_encode_string(struct mbim_string *str, char *in) { - int l = strlen(in); - int s = mbim_add_payload(l * 2); + const int l = strlen(in); + const int utf16_len = l * 2; + const int pad_len = utf16_len % 4; + const int s = mbim_add_payload(utf16_len + pad_len); uint8_t *p = &payload_buffer[s]; int i; @@ -62,14 +64,15 @@ mbim_encode_string(struct mbim_string *str, char *in) return -1; str->offset = htole32(s); - str->length = htole32(l * 2); + str->length = htole32(utf16_len); + + /* convert to utf-16 little endian */ for (i = 0; i < l; i++) - p[i * 2] = in[i]; + p[i * 2] = htole16(in[i]); return 0; } - char * mbim_get_string(struct mbim_string *str, char *in) {