From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x2257nNjlt0ElpKoiwjlGr8m7dQOG0YVusX/AuBCw7Q+fR8yBzB6BNU5cL+tq/N2wLGpvrPQD ARC-Seal: i=1; a=rsa-sha256; t=1517256899; cv=none; d=google.com; s=arc-20160816; b=p1uYYafLU2XcDD8rkQYsY0JpJVUq9tlZ+VVOL3iJFY35u8w5QtAUVuPVzYXkO9U1WA NKwHszo7p4JrLgeevAqa1WmoVATVbUNV8Kfd6CBbxnc1Es9ofNZ0S67olEtuwZNCE8Ac cWpP6j3MKGxqwb+OIGfHLjkhOB9MyAjFtPKuFtms46kOei6JLymV0e/VJobktOUQfjLK EcQjsCQbfkGmSoUYNRQ6WZ7KKoHLmw+7Yy1hkZ7VEEXJIFTGFyV6H0CCg+89KlJxnNaG bcc7osV/Ul1wLCAxs1yI7XMep5x0sPDbtbMf9oMdPtnqMCGx/uMBtxOZBiPJSBR31v3/ FRFg== 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=BtKDVTUdbMqWTTLEMnjUtzjkSVnG4akBNNo0Iu1Euxc=; b=zEuLpqme7gTUDSCtnRyaqpbR9NTwgMXdzYwS/Kql3XqOm+oQWUIrxHOkazuc664u6x qgu+hM9Gkhf8Xe7f4wSrBTDVPrX/QyimR50lUtfuy9z2ZB/Dku+Ty8Fr/kr4gP0BOHEM 3sXUzK1GXpOz+42nLQ80vvbroRFaQOWCVgMobE7j9cAC4CTi99uHm9sQWr5Vpn7Bjdyc 9YVo2G5ANf026FV9JPT4GMr3mFX4iaoj3nXA6Ze1rvgk8pQuyGcZ55lugbyY255hCMAL eX7FsaXNcp1vbQ11ZpxcPlPar/6KKavqo4duXU2ZBgoUzxiPHjqmeLFSoZXgbQWc7FXd 2qiQ== 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 3.18 06/52] af_key: fix buffer overread in verify_address_len() Date: Mon, 29 Jan 2018 13:56:24 +0100 Message-Id: <20180129123628.467739182@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180129123628.168904217@linuxfoundation.org> References: <20180129123628.168904217@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?1590959171196488616?= X-GMAIL-MSGID: =?utf-8?q?1590959171196488616?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: 3.18-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));