Received: by 10.223.176.46 with SMTP id f43csp2688578wra; Mon, 22 Jan 2018 01:38:06 -0800 (PST) X-Google-Smtp-Source: AH8x226ryLobbS+IsBBWRMtUfSj3WEaV+f3nOZDihMr4r1nd3DqQ003SvrMPA6KSgP3NOqZPPa9H X-Received: by 2002:a17:902:7b8f:: with SMTP id w15-v6mr3154389pll.219.1516613886087; Mon, 22 Jan 2018 01:38:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516613886; cv=none; d=google.com; s=arc-20160816; b=gGEiTw/HfmWqcU/zHoS5oWEHRstESP7LrwwwtOc753w/MFpycKqv1i/FxKGOpj/l7L 1pkM+YxQPy3JFIGf2ewr8jJ9lgujZE/GXuRTnu5hTAV8Y2lF8ZcEKoxEmuRcncx0/or1 FTlWQA6EBqOiJjrvVH8QPpbLjAyjiVFmCo4ZYVQ6F1uzyIXS5VrsYVMZDkTPoLM3k8jC wr1ZccaMyEySI1G0j4E2Q6zYSs1r7ce7mv7MnmeaU31/iQ/SH082nczcxU7XVHQApIIb JS9ksFAnNdI3IJFJlRaG3uaDhaZDGhS6XWk56fJ7bZ4H77DK6JeU3pbUfwOI4CEnbHeO PRuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Cb8D0wnaQaUpb+4M8D3KTgwjGZbbQPTpgXXcQxK03DY=; b=uv3vwhmjG0kWzxMw1draiMnG9D9xFtoe4Vz+ji0NDXjBxXA3T8hkoI81y4zqVURfS/ EZTOzzj0VI/lkWMt5dwi1sbMmRzmTcVaHDxHHn4KxO0E3q4V6t1INyN9z3Skn0QP4HRl YLW9YuVG0HdlH3YUtc8gMdLi5vD8pw4aP+4bUhDZbyw6EXIh6u1o1OPRlN0Pc4fHq+tI VY1Bv9z9l58YOPigEgJcQi0aSgRvd+fXYXBQWXmAu520ZcKx0F3HFlV+ew2Scrs4Ggse D2qnYzBQlUE9DcPlbXyccAc4eXixwPj08NywBybtBqB3rG9VXuioZb9yAP6EaXVEDLLP g8VQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bd5-v6si3230736plb.431.2018.01.22.01.37.51; Mon, 22 Jan 2018 01:38:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751618AbeAVJg7 (ORCPT + 99 others); Mon, 22 Jan 2018 04:36:59 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:60394 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751812AbeAVIse (ORCPT ); Mon, 22 Jan 2018 03:48:34 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 43543E53; Mon, 22 Jan 2018 08:48:33 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Potapenko , Eric Biggers , Steffen Klassert Subject: [PATCH 4.9 09/47] af_key: fix buffer overread in verify_address_len() Date: Mon, 22 Jan 2018 09:45:20 +0100 Message-Id: <20180122083926.182645858@linuxfoundation.org> X-Mailer: git-send-email 2.16.0 In-Reply-To: <20180122083925.568134913@linuxfoundation.org> References: <20180122083925.568134913@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Biggers commit 06b335cb51af018d5feeff5dd4fd53847ddb675a upstream. If a message sent to a PF_KEY socket ended with one of the extensions that takes a 'struct sadb_address' but there were not enough bytes remaining in the message for the ->sa_family member of the 'struct sockaddr' which is supposed to follow, then verify_address_len() read past the end of the message, into uninitialized memory. Fix it by returning -EINVAL in this case. This bug was found using syzkaller with KMSAN. Reproducer: #include #include #include int main() { int sock = socket(PF_KEY, SOCK_RAW, PF_KEY_V2); char buf[24] = { 0 }; struct sadb_msg *msg = (void *)buf; struct sadb_address *addr = (void *)(msg + 1); msg->sadb_msg_version = PF_KEY_V2; msg->sadb_msg_type = SADB_DELETE; msg->sadb_msg_len = 3; addr->sadb_address_len = 1; addr->sadb_address_exttype = SADB_EXT_ADDRESS_SRC; write(sock, buf, 24); } Reported-by: Alexander Potapenko Signed-off-by: Eric Biggers Signed-off-by: Steffen Klassert Signed-off-by: Greg Kroah-Hartman --- net/key/af_key.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/net/key/af_key.c +++ b/net/key/af_key.c @@ -401,6 +401,11 @@ static int verify_address_len(const void #endif int len; + if (sp->sadb_address_len < + DIV_ROUND_UP(sizeof(*sp) + offsetofend(typeof(*addr), sa_family), + sizeof(uint64_t))) + return -EINVAL; + switch (addr->sa_family) { case AF_INET: len = DIV_ROUND_UP(sizeof(*sp) + sizeof(*sin), sizeof(uint64_t));