Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5583810img; Wed, 27 Mar 2019 11:08:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvaorSBEB3dzNz96x8sSG8RmtIedRm1lkIw5jwC+iSLUteaECcQq83bVetHV6h+sPy3A02 X-Received: by 2002:a63:2ad4:: with SMTP id q203mr36491865pgq.43.1553710122966; Wed, 27 Mar 2019 11:08:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553710122; cv=none; d=google.com; s=arc-20160816; b=n/y9S8VOjN1VdkLnC4X8LiJhlo0HmBqtUdbOVbafZhWJVJ8I2PIYYlFFfrTUaJBqc6 1CWL05hUbXYq2O3Fl8RRiuG0gAFOo2wXK7uCNk55XqzaK2FgBJZp/JHzGF2cO7i8b5SI 5M4jm2Glz3y2DCvFfu4a7MJC4PMfxL7HxRgGfRig7w8oYC9c7A2PtLAoXLkUf8Gs8nJj t8zCDxrvNNIm0PRFEqO3LIJUD+2rmFUT5y/V4Oo4J2UWzSTFLEYBy8lKms2Mrxp13k/i HcEmAbe0C1dPVzC42hAk0JhQVP5ndTSHR0+fsAfTWPDtz0nV6txJSMekbNqn27sLN5+q EVnQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5vCWsqyb7sqNdJeXJdXffzMIeCNRys70d9oIsq+V9zE=; b=NO3T5FOx5ASNC6cuQf/QKJOLoenaJU+TRbaXW9kZ6w8D92OqZC8umlSyHql99NOT7h iFx+JDmszTL3mWdp0/AT14Q/26dTkUNC2dnczFH51EqW48+yS60Lmfu0X10qlF+ZbHtz 8P6jAvnGZk0eLMVhMobU0DO8R6G728ZZjyj17sZqGiH2POB/zH/jlD9Yf54B2QLhV9Ai j2MY3wabd+cX09uF8ITGkyWLdGD27M8+HuL+j2GwQe0/3hSoCHja6N8blp5sYeNL6vZb Ni1Kslpr6yowTFMoP8J/S6OGUhnRUQkyzNPux8hIFiQOXLHofNUAdk9lPNPnp2Vt8W2t uCyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="L/k15ViJ"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w7si18336158pgs.155.2019.03.27.11.08.27; Wed, 27 Mar 2019 11:08:42 -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="L/k15ViJ"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388107AbfC0SHI (ORCPT + 99 others); Wed, 27 Mar 2019 14:07:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:48898 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388079AbfC0SHE (ORCPT ); Wed, 27 Mar 2019 14:07:04 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 87B23217F5; Wed, 27 Mar 2019 18:07:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553710024; bh=z33zI+NWbvIGBxzK4c2sPjhHdAfkNayBihcOTJjsxGI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L/k15ViJxpmQg561HWvzyU7084NzNZ9cHntWhQzt+bO9o+CHNSbkqoomm1tTaBC5B uWs+IwUqFK4HHCEHAExr4Rflf42pQDF/eOBv4YJLKBh9vEUySbP4n3P74RuWBZi/8E qUqQc5zohTaLesphPW+pxatFhjsMjbfNuf6wcTlE= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Coly Li , Jens Axboe , Sasha Levin , linux-bcache@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 161/262] bcache: fix input overflow to sequential_cutoff Date: Wed, 27 Mar 2019 14:00:16 -0400 Message-Id: <20190327180158.10245-161-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Coly Li [ Upstream commit 8c27a3953e92eb0b22dbb03d599f543a05f9574e ] People may set sequential_cutoff of a cached device via sysfs file, but current code does not check input value overflow. E.g. if value 4294967295 (UINT_MAX) is written to file sequential_cutoff, its value is 4GB, but if 4294967296 (UINT_MAX + 1) is written into, its value will be 0. This is an unexpected behavior. This patch replaces d_strtoi_h() by sysfs_strtoul_clamp() to convert input string to unsigned integer value, and limit its range in [0, UINT_MAX]. Then the input overflow can be fixed. Signed-off-by: Coly Li Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/md/bcache/sysfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c index 3b287f974fd9..f98cda32065d 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -299,7 +299,9 @@ STORE(__cached_dev) dc->io_disable = v ? 1 : 0; } - d_strtoi_h(sequential_cutoff); + sysfs_strtoul_clamp(sequential_cutoff, + dc->sequential_cutoff, + 0, UINT_MAX); d_strtoi_h(readahead); if (attr == &sysfs_clear_stats) -- 2.19.1