Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2508547imm; Mon, 24 Sep 2018 05:39:37 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdbfx2Kx43la/CXPhuj1FsmugsWAPCtp1SgXONcJGuAEJI7fd8B43W46KGlTKtjedaG1z8jF X-Received: by 2002:a62:5306:: with SMTP id h6-v6mr5053428pfb.54.1537792776970; Mon, 24 Sep 2018 05:39:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537792776; cv=none; d=google.com; s=arc-20160816; b=nSvQeSD2DAcBrGW39+9l9yMr/+ggTNV+BWbhbcbsJITxDXj/Wa1rqb/qvGbh+X1alm fMWLrnLw01xI1taP/Zz1VvOHkPGkM+lm4zMo9zOlk+uJ5Dszt/kOiG2V4bGTrwLE90XC jCadB1zBfYegh6vV1+qSM2QI8vCP+EBLU+j1Z0qYeCIZnVIyFWClKVUGFfsFGvEh5VnD ps8+8ZGURylqP+DLbUe7SVPrLf1ih2XCnoWsWVItQSclWRhZE4Wx+sxACINS7vw13eAX E2CJ0ueCluGagbSur5Ggi4aSbT8N4bQZoGzV+Bo4QCrG2Vrgg1U+XoYM9zL9EmtAPI/c UieA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=UUm/tJi0X2U20GFC6bloWenUSzcD1GKhHY2P0VDxiRI=; b=jKBHLBErs8IcwsRjbqNOV7sV7sbus5xhx6vjMKUTfG1+hsSafFyGStVZMyHUZlanXw rY+SQhCnoBellEBqmU6GH9+FtfLyfdWTwdpLPWrmH5aRQHLI+E1X9w2MBYOwGT+WfO8T ht214fcY+DCL8xhjbfWX7ybeXxn4OkkP+2pW6+8XxHc5G2NFqF/6UVb5WQjLxkhM0rRB fbY9DGaPfNh9ZhoTdxSnHVbkCFE+eE9Usm/MptXqdeJbRZ4xufXRCs2NXG9Z0X/wqnvr 9Ac2uDpgEA+UZw8VjfIz49Lp/8uPslBsTIVK9gxh2w1r+KjfFfMYv0D74YIMhfmrT/wJ WLsA== 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 b1-v6si33210337plc.168.2018.09.24.05.39.21; Mon, 24 Sep 2018 05:39:36 -0700 (PDT) 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 S2388105AbeIXSkP (ORCPT + 99 others); Mon, 24 Sep 2018 14:40:15 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58694 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729893AbeIXSkO (ORCPT ); Mon, 24 Sep 2018 14:40:14 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id B54101097; Mon, 24 Sep 2018 12:38:17 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dr Silvio Cesare of InfoSect , Ronnie Sahlberg , Aurelien Aptel , Dan Carpenter , Steve French Subject: [PATCH 4.18 134/235] cifs: prevent integer overflow in nxt_dir_entry() Date: Mon, 24 Sep 2018 13:52:00 +0200 Message-Id: <20180924113119.219693091@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180924113103.999624566@linuxfoundation.org> References: <20180924113103.999624566@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dan Carpenter commit 8ad8aa353524d89fa2e09522f3078166ff78ec42 upstream. The "old_entry + le32_to_cpu(pDirInfo->NextEntryOffset)" can wrap around so I have added a check for integer overflow. Reported-by: Dr Silvio Cesare of InfoSect Reviewed-by: Ronnie Sahlberg Reviewed-by: Aurelien Aptel Signed-off-by: Dan Carpenter Signed-off-by: Steve French CC: Stable Signed-off-by: Greg Kroah-Hartman --- fs/cifs/readdir.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/fs/cifs/readdir.c +++ b/fs/cifs/readdir.c @@ -376,8 +376,15 @@ static char *nxt_dir_entry(char *old_ent new_entry = old_entry + sizeof(FIND_FILE_STANDARD_INFO) + pfData->FileNameLength; - } else - new_entry = old_entry + le32_to_cpu(pDirInfo->NextEntryOffset); + } else { + u32 next_offset = le32_to_cpu(pDirInfo->NextEntryOffset); + + if (old_entry + next_offset < old_entry) { + cifs_dbg(VFS, "invalid offset %u\n", next_offset); + return NULL; + } + new_entry = old_entry + next_offset; + } cifs_dbg(FYI, "new entry %p old entry %p\n", new_entry, old_entry); /* validate that new_entry is not past end of SMB */ if (new_entry >= end_of_smb) {