Received: by 10.223.185.116 with SMTP id b49csp6430304wrg; Wed, 28 Feb 2018 09:16:00 -0800 (PST) X-Google-Smtp-Source: AH8x226xNdvh7ensO1TQdU+rrrR7fzalIZtnK3GrD3XF+WwrFWKcnsTRfDuQi4OYi+OGFl2P2Rah X-Received: by 10.101.83.194 with SMTP id z2mr14796176pgr.133.1519838160670; Wed, 28 Feb 2018 09:16:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519838160; cv=none; d=google.com; s=arc-20160816; b=tXODQlxNxwa6OvtXx1LmsQ7o4HDa/OpRJNimR105Wy/tmNVnR8y8mHNa/MCDQj5n82 ovhf+uYrSGIABfUyeu5dUI3ejFy7XFP4Iu1kHEW84UPyPSrToafpQ98vU7tLS6C+5kc3 Ovwq4IL6SxKdlJ8lKMhwroo8YZwEv2ol7EBKpnY4jKO9jjEmv+U1P3VaS3X+5iN+GAds 1LqTyNbkz4Ro9Lfyvug5fI2i8BdrDtVpoH6i1MDux04Pc9PoL8bP4LVrjjC6/FLDTi0J +DsW+xn0+HleTcVyajx8qU/tcAGDZ21gSPbc9xa7vMVyfgiVWTzjWzWoZkBj2vZRG/tu z5PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=0XBsSQKWBwSxDRcgC4dgyo33mEmIf76uKkMGZczJkWA=; b=Emx1PCdL7zMdpsY5S4Q8+nyGBGxfZFLJwkyPNFjUAArGpIAYEEEA4VpyS9m/5/jxzy C4exki8W1Ty45/axNh0X9mcpgJC4VqYrFeROlWj5u+OYmTwCOC7UQ/GXMp7Hx2ZNEEfY KLSB4ciqBoFDhi6S174EBE9B96xCcnRKzRDvxrgxZ0F8mB/0svbplC5GcEzQ4QrktcH9 8nfOWkIjbL69NZHh0ucYQgcKOKEcSIGOkIsUXcg/+OdWw8YqnZyAKVaJqFviyFQQJZuK A7Sz4KkXANjRpHr3Gu1sRZ6OVGfeBr9Y9GQq08CpyaMFoggnnKmXG2JojqniUPFnbbbB LzRw== 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 m12-v6si1523601pln.400.2018.02.28.09.15.44; Wed, 28 Feb 2018 09:16:00 -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 S933814AbeB1RNk (ORCPT + 99 others); Wed, 28 Feb 2018 12:13:40 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:34284 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752848AbeB1Ptu (ORCPT ); Wed, 28 Feb 2018 10:49:50 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1er3Yr-0006Xg-LC; Wed, 28 Feb 2018 15:22:29 +0000 Received: from ben by deadeye with local (Exim 4.90_1) (envelope-from ) id 1er3Yi-0000AM-12; Wed, 28 Feb 2018 15:22:20 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Eric Biggers" , "Steffen Klassert" , "Alexander Potapenko" Date: Wed, 28 Feb 2018 15:20:18 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 150/254] af_key: fix buffer overread in verify_address_len() In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.55-rc1 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: Ben Hutchings --- net/key/af_key.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/net/key/af_key.c +++ b/net/key/af_key.c @@ -397,6 +397,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));