Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2188515ybm; Thu, 23 May 2019 12:49:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqwNgzRekBJJMjX76DBUiAQVM5vcerR/qqySkaLU3yjK6h89ugZrpB2SgzTtyYwn4KK4ib36 X-Received: by 2002:a65:64d5:: with SMTP id t21mr26265818pgv.310.1558640983534; Thu, 23 May 2019 12:49:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558640983; cv=none; d=google.com; s=arc-20160816; b=wyJQXcek4YfmYOTSJjCxv58h+K+1RKWhTexjsxjB0S59xVWW5as9etF8MYZrOWzfbQ LcQN/fnstXBQmNVADvGMNpGHUY+0xv7LrE0wl+4K8GDHQbfbTm88Kh9UI4jDGz35KNMn 3A0apbJTFOVNE02mHYbr+dLuSg/QAaiP3d5uNAhPJ5ONjxg+K+aq++hU1vZ0u9lz47IJ O9kLIBLLvZ3wQsKDbuqSYjblvj0ZUdlId5qZj0rcXA6I/x5RUaJHX8oCwpqEiS6wkkBK UvTfD4iRQXjkzcmpZXW1TgIZPdcWh1u5ybuvzBrEg52qu83n/cMG+0Hx5dLnCXJcPyGk rYIg== 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:dkim-signature; bh=k3FCP/gDDs0T7G6vi89/PqNk+kSsjedVFV7bykHaKeA=; b=rU7WPqF7LvfhhdQpxuaUEqySpPuG6UqZEUXUvcDGI1qFoO+3q/S6O7GJ5Z9286rPGC /YGusbYZiAnAAUKUHqBGcVe+AZUqiPJXKKGIOjdnt0Rzt21ZkckeZ833A2uI6tIyV8zI /YF1SEpxnci0/sr1UkK36qIgx2jnvN41m58YS6ddV1iA7TelON86CqDBHP//ch7DeHIf on2YKd3jOjPldqCgXid/kkqSJ4PnjzOwN7a17L9nYWbEEoYf8/g0mVj1rNyA+0iUvmAa y+vhaVfIs4EpUkrFsPvT2rI5l9wPKefZSCh63uvUAkxqbn84YRL5yx/hsh1X002C2VvF JQvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1euzmsfz; 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 x23si684432plr.149.2019.05.23.12.49.27; Thu, 23 May 2019 12:49:43 -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; dkim=pass header.i=@kernel.org header.s=default header.b=1euzmsfz; 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 S2388314AbfEWTL4 (ORCPT + 99 others); Thu, 23 May 2019 15:11:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:45418 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388305AbfEWTLx (ORCPT ); Thu, 23 May 2019 15:11:53 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 875C621850; Thu, 23 May 2019 19:11:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558638713; bh=hiCb3R+vMwy2kF6IAVltpcOZWA/Dwo4jtFRNYYTVGEg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1euzmsfzhCyUzLx97mVhkthEo2U6IluX3vBYWSwQTGoueZTR5uIPLkvz6ayaUlpOQ lLMnJLJHLAIZNVb6V6wbb1mCgT/dWDK66JZAPl67cup2jgO8W6BE6pAXxUS+q8JXR3 OW0Za8HXZ1r9Qj0c4quoqwh8NRUrSgNsJAsSp/I0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Probst , Pavel Shilovsky , Steve French Subject: [PATCH 4.14 20/77] cifs: fix strcat buffer overflow and reduce raciness in smb21_set_oplock_level() Date: Thu, 23 May 2019 21:05:38 +0200 Message-Id: <20190523181723.075830718@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523181719.982121681@linuxfoundation.org> References: <20190523181719.982121681@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Christoph Probst commit 6a54b2e002c9d00b398d35724c79f9fe0d9b38fb upstream. Change strcat to strncpy in the "None" case to fix a buffer overflow when cinode->oplock is reset to 0 by another thread accessing the same cinode. It is never valid to append "None" to any other message. Consolidate multiple writes to cinode->oplock to reduce raciness. Signed-off-by: Christoph Probst Reviewed-by: Pavel Shilovsky Signed-off-by: Steve French CC: Stable Signed-off-by: Greg Kroah-Hartman --- fs/cifs/smb2ops.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -1969,26 +1969,28 @@ smb21_set_oplock_level(struct cifsInodeI unsigned int epoch, bool *purge_cache) { char message[5] = {0}; + unsigned int new_oplock = 0; oplock &= 0xFF; if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) return; - cinode->oplock = 0; if (oplock & SMB2_LEASE_READ_CACHING_HE) { - cinode->oplock |= CIFS_CACHE_READ_FLG; + new_oplock |= CIFS_CACHE_READ_FLG; strcat(message, "R"); } if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) { - cinode->oplock |= CIFS_CACHE_HANDLE_FLG; + new_oplock |= CIFS_CACHE_HANDLE_FLG; strcat(message, "H"); } if (oplock & SMB2_LEASE_WRITE_CACHING_HE) { - cinode->oplock |= CIFS_CACHE_WRITE_FLG; + new_oplock |= CIFS_CACHE_WRITE_FLG; strcat(message, "W"); } - if (!cinode->oplock) - strcat(message, "None"); + if (!new_oplock) + strncpy(message, "None", sizeof(message)); + + cinode->oplock = new_oplock; cifs_dbg(FYI, "%s Lease granted on inode %p\n", message, &cinode->vfs_inode); }