From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751201AbcLEGOk (ORCPT ); Mon, 5 Dec 2016 01:14:40 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:60872 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750746AbcLEGOj (ORCPT ); Mon, 5 Dec 2016 01:14:39 -0500 Message-ID: <5845055F.2090203@huawei.com> Date: Mon, 5 Dec 2016 14:12:47 +0800 From: Xishi Qiu User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 MIME-Version: 1.0 To: "Eric W. Biederman" CC: Yisheng Xie , Andrew Morton , , , , , , , , , , , Subject: Re: [PATCH] kernel/sysctl: return -EINVAL if write invalid val to ulong type sysctl References: <1480501852-36968-1-git-send-email-xieyisheng1@huawei.com> <20161130133358.d508cc8931be6f08ee88561f@linux-foundation.org> <97ca5661-fcae-fe34-810b-d5c6843289e7@huawei.com> <87fum616eg.fsf@xmission.com> In-Reply-To: <87fum616eg.fsf@xmission.com> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.25.179] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2016/12/3 3:24, Eric W. Biederman wrote: > Yisheng Xie writes: > >> On 2016/12/1 5:33, Andrew Morton wrote: >>> On Wed, 30 Nov 2016 18:30:52 +0800 Yisheng Xie wrote: >>> >>>> I tried to echo an invalid value to an unsigned long type sysctl on >>>> 4.9.0-rc6: >>>> linux:~# cat /proc/sys/vm/user_reserve_kbytes >>>> 131072 >>>> linux:~# echo -1 > /proc/sys/vm/user_reserve_kbytes >>>> linux:~# cat /proc/sys/vm/user_reserve_kbytes >>>> 131072 >>>> >>>> The echo operation got error and the value do not write to >>>> user_reserve_kbytes, however, user do not know it until checking >>>> the value again. >>>> >>>> This patch return -EINVAL when write an invalid value to unsigned >>>> long type sysctl to make user know what happened without >>>> checking its value once more, just as what proc_douintvec do. >>> >>> hmpf. >>> >>> # echo 18446744073709551615 > /proc/sys/vm/user_reserve_kbytes >>> # cat /proc/sys/vm/user_reserve_kbytes >>> 18446744073709551615 >>> >>> I think that when taking in an unsigned long the kernel should simply >>> treat -1 as 0xffffffff (or 0xffffffffffffffff). It's natural and >>> normal and everyone knows what it means? >>> >> Hi Andrew, >> Thank you for your reply. >> Do you means it should be like this: >> # echo -1 > /proc/sys/vm/user_reserve_kbytes >> # cat /proc/sys/vm/user_reserve_kbytes >> 18446744073709551615 >> >> I looks ok to me, however, I not sure whether other code in the kernel >> will also use its complement if user write a negative number for an >> unsigned long. Does anyone have other opinion ? > > Largely we need to be very careful with changing these functions as > they have been around for a long time, and have a very diverse set of > users. > > So while changes are possible a reasonable argument needs to be made > that nothing in userspace cares. > > Eric > Hi Eric, This patch is aimed to change the return value if write invalid value to ulong type sysctl, just to keep the same as int type sysctl. Thanks, Xishi Qiu > . >