From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753936AbdKFXZJ (ORCPT ); Mon, 6 Nov 2017 18:25:09 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:51625 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753185AbdKFXXq (ORCPT ); Mon, 6 Nov 2017 18:23:46 -0500 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, "Ronnie Sahlberg" , "Steve French" Date: Mon, 06 Nov 2017 23:03:07 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.2 044/147] cifs: return ENAMETOOLONG for overlong names in cifs_open()/cifs_lookup() 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 List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.2.95-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Ronnie Sahlberg commit d3edede29f74d335f81d95a4588f5f136a9f7dcf upstream. Add checking for the path component length and verify it is <= the maximum that the server advertizes via FileFsAttributeInformation. With this patch cifs.ko will now return ENAMETOOLONG instead of ENOENT when users to access an overlong path. To test this, try to cd into a (non-existing) directory on a CIFS share that has a too long name: cd /mnt/aaaaaaaaaaaaaaa... and it now should show a good error message from the shell: bash: cd: /mnt/aaaaaaaaaaaaaaaa...aaaaaa: File name too long rh bz 1153996 Signed-off-by: Ronnie Sahlberg Signed-off-by: Steve French [bwh: Backported to 3.2: name checks are done only in cifs_lookup()] Signed-off-by: Ben Hutchings --- --- a/fs/cifs/dir.c +++ b/fs/cifs/dir.c @@ -520,6 +520,13 @@ cifs_lookup(struct inode *parent_dir_ino oplock = pTcon->ses->server->oplocks ? REQ_OPLOCK : 0; + /* Don't allow path components longer than the server max. */ + if (unlikely(direntry->d_name.len > + pTcon->fsAttrInfo.MaxPathNameComponentLength)) { + rc = -ENAMETOOLONG; + goto lookup_out; + } + /* * Don't allow the separator character in a path component. * The VFS will not allow "/", but "\" is allowed by posix.