Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751518AbdF1PAv (ORCPT ); Wed, 28 Jun 2017 11:00:51 -0400 Received: from mail-wr0-f180.google.com ([209.85.128.180]:36380 "EHLO mail-wr0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751642AbdF1PAn (ORCPT ); Wed, 28 Jun 2017 11:00:43 -0400 From: Alexander Potapenko To: dvyukov@google.com, kcc@google.com, davem@davemloft.net, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH] sysctl: don't read uninit memory in deprecated_sysctl_warning() Date: Wed, 28 Jun 2017 17:00:37 +0200 Message-Id: <20170628150037.3809-1-glider@google.com> X-Mailer: git-send-email 2.13.2.725.g09c95d1e9-goog Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 810 Lines: 25 Don't attempt to read the first two elements of name[] unless they were actually copied from the userspace. This bug has been detected by KMSAN. Signed-off-by: Alexander Potapenko --- kernel/sysctl_binary.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c index ece4b177052b..38d6ba22a209 100644 --- a/kernel/sysctl_binary.c +++ b/kernel/sysctl_binary.c @@ -1346,7 +1346,7 @@ static void deprecated_sysctl_warning(const int *name, int nlen) * CTL_KERN/KERN_VERSION is used by older glibc and cannot * ever go away. */ - if (name[0] == CTL_KERN && name[1] == KERN_VERSION) + if (nlen >= 2 && name[0] == CTL_KERN && name[1] == KERN_VERSION) return; if (printk_ratelimit()) { -- 2.13.2.725.g09c95d1e9-goog