From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x2260WnPUt9NZUuZzsVX8zaeWvbJNT5PflTES2Q+sSuIzbI/tuRAFBI4X3ffl6hs8USf1SDZ+ ARC-Seal: i=1; a=rsa-sha256; t=1516610504; cv=none; d=google.com; s=arc-20160816; b=Fj+AmGW/g8gbHxt8YC9rpAvKSfvgXbnHk7wv7EOpUlpt9BWQmOavuN6dVZ59rhoYkW i2zOq2L1Kg6gYSwAtx+YORCuyyQChPnoFLrQXqPzSOETJvk8US/oZ8euUoFUIc7Tfzhm 82cCU0Xzl16ilbBfSKEZ7vXQ2FY6md9EPkLJ1S0HiEbc921OthQTbxcrKdy0h/X3amEq dNIYDf6JyW3rDC5hOvq621+SLwWctJ2OUHX3HMDdQyacGGx9c16FRVaYFpzMPDk43ywl grDPhBcZKWttPEHmiu3PQuKGJo7f3WEVJFoJj6pQvFTQZAWsf3ZMA+kCOlkCyKK6t7Ai zM5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=k0kgQBvmJu8t5WvbCMBspWbiqIwNZ2+obE1VaKXaBZE=; b=biXcSADIfSTWgVVdpI+uzk7ecfznz8Y5oM4RJHjrZATs4DFxMIFeB1lK3E79mpBg4v THDjDzeNg/x7c6EsV/Vjbv+yTbkvrrT9Q6oa580gwkdYd/ORlqmgF5JPk3cP4DIMPb7y xgwOI5FTcpJ5MoiDpq/fTxXtZZrsyF6ZktbPs2nV3WJcK8nKwomVn8mhmhb/GlNiqrOg FvJwFhaU9P4Ee+qSF1y9aqDX7QnUb88wjyej7t0eb6C+DzT375GisYwTKKrUIec/XugV sJvY+cUxYghvutCECxKYV9ml5kNvCiIp2YCF7XwJHLu0YC/E6Lt3pGXhe04IXBN7RXE5 j72A== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 90.92.71.90 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 90.92.71.90 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org 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.4 26/53] af_key: fix buffer overread in verify_address_len() Date: Mon, 22 Jan 2018 09:40:18 +0100 Message-Id: <20180122083911.441121572@linuxfoundation.org> X-Mailer: git-send-email 2.16.0 In-Reply-To: <20180122083910.299610926@linuxfoundation.org> References: <20180122083910.299610926@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-LABELS: =?utf-8?b?IlxcU2VudCI=?= X-GMAIL-THRID: =?utf-8?q?1590281377007342439?= X-GMAIL-MSGID: =?utf-8?q?1590281377007342439?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: 4.4-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));