From patchwork Wed May 24 10:26:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Jurczyk X-Patchwork-Id: 9745725 X-Patchwork-Delegate: sameo@linux.intel.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9337D60209 for ; Wed, 24 May 2017 10:27:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B08328936 for ; Wed, 24 May 2017 10:27:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F8572894A; Wed, 24 May 2017 10:27:12 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable 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 2E3E828936 for ; Wed, 24 May 2017 10:27:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760595AbdEXK1J (ORCPT ); Wed, 24 May 2017 06:27:09 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:38699 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030368AbdEXK03 (ORCPT ); Wed, 24 May 2017 06:26:29 -0400 Received: by mail-wm0-f51.google.com with SMTP id e127so68284768wmg.1 for ; Wed, 24 May 2017 03:26:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=DA1U225Tp0W6hbOiqQQH8j+77g9IrBqqxYFg4sbcz+M=; b=lnimOoAjA0xGVCo29gV8eR9QQk4i0x/DFLO1yrluie1qy/fnNgkeX+f/WjccA0K6aa V/uo+OY3DOzjDukPFLCP0Xpl6okMJPbs2klwtd6n7/bezzF+3N3kDbf3Kt7D1/7c20Nc IQ4eoG2xQz3P2te+B7wmERCVA2Cz+OCee8tEPL4CnDArfIh8d0y8BvQ/degSF2H42RnA pjPgniKW3q6nsU5yYsKOSmbyiEeiGb5qDqE/gmkuLnWR+lZX2hmbkDumMflrTtDirvgV 7IsDr5l5GfxEwm2D6cPLlEMfHLEzk5Bw58R/UnVKj4gcuOdQSjhglp8upqKpjfXqd7B6 MoZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=DA1U225Tp0W6hbOiqQQH8j+77g9IrBqqxYFg4sbcz+M=; b=Cmiba9z/uZqK5I0v6PvDRNPl1rPvsO6sPbJ5X5bK0leumrdiWK4xcBe8EmLMaFe08q rJv7KTF5C7fgy4Ihy9eih+oL4B9ykZkAsWvQTQcnjMq9SQ1B93l005HpPhYJkyZ8fGD/ 6ljSc/cG3yVVYhy7g21bSk6oYMA3ZIwsBvvfTfxJP67PtUtypjKBccDhmDPNP0kYL5/D X9NV1YXGuWsL6BBS0mGy6HhHv96Kcv9AUgBED3Zkji4GVua2wclEQrKa3ygG/U4Yuces wXuup7E9FrIS9qZmThoap6PkJkHWIR4xznIeIBv76yLoihHcHhpZevCE50lZLMg6+2Bi Ft1g== X-Gm-Message-State: AODbwcAZrLwZMXPuEY24xHFcmqOmq5J2SAf8UhEyNd4iB/HCOSlTrF1N zdlpJRB7O61NikaXHEpIKw== X-Received: by 10.223.161.20 with SMTP id o20mr22502060wro.102.1495621582764; Wed, 24 May 2017 03:26:22 -0700 (PDT) Received: from mjurczyk.krp.corp.google.com ([172.28.242.6]) by smtp.gmail.com with ESMTPSA id a24sm4775028wra.17.2017.05.24.03.26.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 May 2017 03:26:22 -0700 (PDT) From: Mateusz Jurczyk To: Samuel Ortiz , "David S. Miller" Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, security@kernel.org Subject: [PATCH] nfc: Fix the sockaddr length sanitization in llcp_sock_connect Date: Wed, 24 May 2017 12:26:20 +0200 Message-Id: <20170524102620.13806-1-mjurczyk@google.com> X-Mailer: git-send-email 2.13.0.219.gdb65acc882-goog Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fix the sockaddr length verification in the connect() handler of NFC/LLCP sockets, to compare against the size of the actual structure expected on input (sockaddr_nfc_llcp) instead of its shorter version (sockaddr_nfc). Both structures are defined in include/uapi/linux/nfc.h. The fields specific to the _llcp extended struct are as follows: 276 __u8 dsap; /* Destination SAP, if known */ 277 __u8 ssap; /* Source SAP to be bound to */ 278 char service_name[NFC_LLCP_MAX_SERVICE_NAME]; /* Service name URI */; 279 size_t service_name_len; If the caller doesn't provide a sufficiently long sockaddr buffer, these fields remain uninitialized (and they currently originate from the stack frame of the top-level sys_connect handler). They are then copied by llcp_sock_connect() into internal storage (nfc_llcp_sock structure), and could be subsequently read back through the user-mode getsockname() function (handled by llcp_sock_getname()). This would result in the disclosure of up to ~70 uninitialized bytes from the kernel stack to user-mode clients capable of creating AFC_NFC sockets. Signed-off-by: Mateusz Jurczyk Acked-by: Kees Cook --- net/nfc/llcp_sock.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c index 2ffb18e73df6..d0d12bea65cb 100644 --- a/net/nfc/llcp_sock.c +++ b/net/nfc/llcp_sock.c @@ -662,8 +662,7 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr, pr_debug("sock %p sk %p flags 0x%x\n", sock, sk, flags); - if (!addr || len < sizeof(struct sockaddr_nfc) || - addr->sa_family != AF_NFC) + if (!addr || len < sizeof(*addr) || addr->sa_family != AF_NFC) return -EINVAL; if (addr->service_name_len == 0 && addr->dsap == 0)