All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] commands/keyctl01: Add new regression test
@ 2017-03-15 11:13 Guangwen Feng
  2017-03-27 13:42 ` Cyril Hrubis
  0 siblings, 1 reply; 7+ messages in thread
From: Guangwen Feng @ 2017-03-15 11:13 UTC (permalink / raw)
  To: ltp

Fixed by:
commit 38327424b40bcebe2de92d07312c89360ac9229a
Author: Dan Carpenter <dan.carpenter@oracle.com>
Date:   Thu Jun 16 15:48:57 2016 +0100

    KEYS: potential uninitialized variable

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
 runtest/commands                      |  1 +
 testcases/commands/keyctl/Makefile    | 24 +++++++++
 testcases/commands/keyctl/keyctl01.sh | 91 +++++++++++++++++++++++++++++++++++
 3 files changed, 116 insertions(+)
 create mode 100644 testcases/commands/keyctl/Makefile
 create mode 100644 testcases/commands/keyctl/keyctl01.sh

diff --git a/runtest/commands b/runtest/commands
index fd51703..682deda 100644
--- a/runtest/commands
+++ b/runtest/commands
@@ -41,3 +41,4 @@ which01 which01.sh
 lsmod01 lsmod01.sh
 insmod01 insmod01.sh
 wc01 wc01.sh
+keyctl01 keyctl01.sh
diff --git a/testcases/commands/keyctl/Makefile b/testcases/commands/keyctl/Makefile
new file mode 100644
index 0000000..144beed
--- /dev/null
+++ b/testcases/commands/keyctl/Makefile
@@ -0,0 +1,24 @@
+#
+#    commands/keyctl testcases Makefile.
+#
+#    Copyright (c) 2017 Fujitsu Ltd.
+#    Author:Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+
+top_srcdir		?= ../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_TARGETS		:= keyctl01.sh
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/commands/keyctl/keyctl01.sh b/testcases/commands/keyctl/keyctl01.sh
new file mode 100644
index 0000000..f50f5f4
--- /dev/null
+++ b/testcases/commands/keyctl/keyctl01.sh
@@ -0,0 +1,91 @@
+#!/bin/sh
+#
+# Copyright (c) 2017 Fujitsu Ltd.
+# Ported: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program, if not, see <http://www.gnu.org/licenses/>.
+#
+# This is a regression test about potential uninitialized variable,
+# the test can crash the buggy kernel, and the bug has been fixed in:
+#
+#   commit 38327424b40bcebe2de92d07312c89360ac9229a
+#   Author: Dan Carpenter <dan.carpenter@oracle.com>
+#   Date:   Thu Jun 16 15:48:57 2016 +0100
+#
+#   KEYS: potential uninitialized variable
+#
+
+TST_ID="keyctl01"
+TST_SETUP=setup
+TST_CLEANUP=cleanup
+TST_TESTFUNC=do_test
+TST_NEEDS_ROOT=1
+TST_NEEDS_TMPDIR=1
+TST_NEEDS_CMDS="keyctl"
+. tst_test.sh
+
+setup()
+{
+	if tst_kvcmp -le 2.6.33; then
+		tst_brk TCONF "Kernel newer than 2.6.33 is needed"
+	fi
+
+	PATH_KEYSTAT="/proc/key-users"
+	PATH_KEYQUOTA="/proc/sys/kernel/keys/root_maxbytes"
+
+	if [ ! -f "$PATH_KEYSTAT" ] || [ ! -f "$PATH_KEYQUOTA" ]; then
+		tst_brk TCONF "'${PATH_KEYSTAT}' or '${PATH_KEYQUOTA}' \
+			does not exist"
+	fi
+
+	ORIG_KEYSZ=`grep -w "0:" $PATH_KEYSTAT | awk '{print $5}' | \
+		cut -d '/' -f1`
+	ORIG_MAXKEYSZ=`cat $PATH_KEYQUOTA`
+}
+
+cleanup()
+{
+	if [ -n "$ORIG_MAXKEYSZ" ]; then
+		echo $ORIG_MAXKEYSZ >$PATH_KEYQUOTA
+	fi
+}
+
+do_test()
+{
+	local maxkeysz=$((ORIG_KEYSZ + 100))
+
+	while true
+	do
+		echo $maxkeysz >$PATH_KEYQUOTA
+
+		keyctl request2 user debug:fred negate @t >temp 2>&1
+		grep -q -E "quota exceeded" temp
+		if [ $? -eq 0 ]; then
+			break
+		fi
+
+		local key=`keyctl show | grep -w "debug:fred" | \
+			awk '{print $1}'`
+		if [ -n "$key" ]; then
+			keyctl unlink $key @s >/dev/null
+			tst_sleep 100ms
+		fi
+
+		((maxkeysz -= 4))
+	done
+
+	tst_res TPASS "Bug not reproduced"
+}
+
+tst_run
-- 
1.8.4.2




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [LTP] [PATCH] commands/keyctl01: Add new regression test
  2017-03-15 11:13 [LTP] [PATCH] commands/keyctl01: Add new regression test Guangwen Feng
@ 2017-03-27 13:42 ` Cyril Hrubis
  2017-03-28  6:46   ` Guangwen Feng
  0 siblings, 1 reply; 7+ messages in thread
From: Cyril Hrubis @ 2017-03-27 13:42 UTC (permalink / raw)
  To: ltp

Hi!
> +	ORIG_KEYSZ=`grep -w "0:" $PATH_KEYSTAT | awk '{print $5}' | \
> +		cut -d '/' -f1`

This looks too complicated for what it does, we can probably simplify
this by something as:

awk -F' +|/' '/0:/ {print $9}' /proc/key-users
      ^        ^     ^
      |        |     This prints last number in the line
      |        This matches lines that contain 0:
      This sets field separator to any sequence of spaces or single /


> +	ORIG_MAXKEYSZ=`cat $PATH_KEYQUOTA`
> +}
> +
> +cleanup()
> +{
> +	if [ -n "$ORIG_MAXKEYSZ" ]; then
> +		echo $ORIG_MAXKEYSZ >$PATH_KEYQUOTA
> +	fi
> +}
> +
> +do_test()
> +{
> +	local maxkeysz=$((ORIG_KEYSZ + 100))
> +
> +	while true
> +	do
> +		echo $maxkeysz >$PATH_KEYQUOTA
> +
> +		keyctl request2 user debug:fred negate @t >temp 2>&1
> +		grep -q -E "quota exceeded" temp
> +		if [ $? -eq 0 ]; then
> +			break
> +		fi
> +
> +		local key=`keyctl show | grep -w "debug:fred" | \
> +			awk '{print $1}'`

Here as well, simple awk '/debug:fred/ {print $1}' should do.

> +		if [ -n "$key" ]; then
> +			keyctl unlink $key @s >/dev/null
> +			tst_sleep 100ms

Is this sleep here necessary? For how much time the test takes?

> +		fi
> +
> +		((maxkeysz -= 4))
> +	done
> +
> +	tst_res TPASS "Bug not reproduced"
> +}
> +
> +tst_run
> -- 
> 1.8.4.2
> 
> 
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [PATCH] commands/keyctl01: Add new regression test
  2017-03-27 13:42 ` Cyril Hrubis
@ 2017-03-28  6:46   ` Guangwen Feng
  2017-03-28  8:34     ` Cyril Hrubis
  0 siblings, 1 reply; 7+ messages in thread
From: Guangwen Feng @ 2017-03-28  6:46 UTC (permalink / raw)
  To: ltp

Hi!

Thanks for your review.

On 03/27/2017 09:42 PM, Cyril Hrubis wrote:
> Hi!
>> +	ORIG_KEYSZ=`grep -w "0:" $PATH_KEYSTAT | awk '{print $5}' | \
>> +		cut -d '/' -f1`
> 
> This looks too complicated for what it does, we can probably simplify
> this by something as:
> 
> awk -F' +|/' '/0:/ {print $9}' /proc/key-users
>       ^        ^     ^
>       |        |     This prints last number in the line
>       |        This matches lines that contain 0:
>       This sets field separator to any sequence of spaces or single /
> 

This is way much better than mine, thanks very much!


awk -F' +|/' '/ 0:/ {print $8}' /proc/key-users
               ^            ^
               |            Sorry, but here should be $8 I suppose
               And here needs a space, to distinguish something like:

    0:     6 5/5 3/200 115/20000
  100:     3 3/3 3/200 84/20000

> 
>> +	ORIG_MAXKEYSZ=`cat $PATH_KEYQUOTA`
>> +}
>> +
>> +cleanup()
>> +{
>> +	if [ -n "$ORIG_MAXKEYSZ" ]; then
>> +		echo $ORIG_MAXKEYSZ >$PATH_KEYQUOTA
>> +	fi
>> +}
>> +
>> +do_test()
>> +{
>> +	local maxkeysz=$((ORIG_KEYSZ + 100))
>> +
>> +	while true
>> +	do
>> +		echo $maxkeysz >$PATH_KEYQUOTA
>> +
>> +		keyctl request2 user debug:fred negate @t >temp 2>&1
>> +		grep -q -E "quota exceeded" temp
>> +		if [ $? -eq 0 ]; then
>> +			break
>> +		fi
>> +
>> +		local key=`keyctl show | grep -w "debug:fred" | \
>> +			awk '{print $1}'`
> 
> Here as well, simple awk '/debug:fred/ {print $1}' should do.
> 

OK, thanks.

>> +		if [ -n "$key" ]; then
>> +			keyctl unlink $key @s >/dev/null
>> +			tst_sleep 100ms
> 
> Is this sleep here necessary? For how much time the test takes?

Yes, it is necessary, without the sleep, this test fails to
reproduce the bug on RHEL7.2GA(buggy kernel), since I found
that it actually takes some time to free the key.


With 100ms sleep, the whole test takes about 2s.


Best Regards,
Guangwen Feng

> 
>> +		fi
>> +
>> +		((maxkeysz -= 4))
>> +	done
>> +
>> +	tst_res TPASS "Bug not reproduced"
>> +}
>> +
>> +tst_run
>> -- 
>> 1.8.4.2
>>
>>
>>
>>
>> -- 
>> Mailing list info: https://lists.linux.it/listinfo/ltp
> 



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [PATCH] commands/keyctl01: Add new regression test
  2017-03-28  6:46   ` Guangwen Feng
@ 2017-03-28  8:34     ` Cyril Hrubis
  2017-03-28 10:37       ` Guangwen Feng
  0 siblings, 1 reply; 7+ messages in thread
From: Cyril Hrubis @ 2017-03-28  8:34 UTC (permalink / raw)
  To: ltp

Hi!
> Yes, it is necessary, without the sleep, this test fails to
> reproduce the bug on RHEL7.2GA(buggy kernel), since I found
> that it actually takes some time to free the key.
> 
> 
> With 100ms sleep, the whole test takes about 2s.

Two seconds is not that bad but can we make it faster? Does the test
still reproduce the issue when we decrease the sleep a bit?

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [PATCH] commands/keyctl01: Add new regression test
  2017-03-28  8:34     ` Cyril Hrubis
@ 2017-03-28 10:37       ` Guangwen Feng
  2017-03-29  2:09         ` [LTP] [PATCH v2] " Guangwen Feng
  0 siblings, 1 reply; 7+ messages in thread
From: Guangwen Feng @ 2017-03-28 10:37 UTC (permalink / raw)
  To: ltp

Hi!

On 03/28/2017 04:34 PM, Cyril Hrubis wrote:
> Hi!
>> Yes, it is necessary, without the sleep, this test fails to
>> reproduce the bug on RHEL7.2GA(buggy kernel), since I found
>> that it actually takes some time to free the key.
>>
>>
>> With 100ms sleep, the whole test takes about 2s.
> 
> Two seconds is not that bad but can we make it faster? Does the test
> still reproduce the issue when we decrease the sleep a bit?
> 

Sleep 50ms still ensure the reproducible in my system,
and it takes no more than 1 second to test, but 30ms
cannot ensure the reproducible.


Best Regards,
Guangwen Feng



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v2] commands/keyctl01: Add new regression test
  2017-03-28 10:37       ` Guangwen Feng
@ 2017-03-29  2:09         ` Guangwen Feng
  2017-03-29 16:53           ` Cyril Hrubis
  0 siblings, 1 reply; 7+ messages in thread
From: Guangwen Feng @ 2017-03-29  2:09 UTC (permalink / raw)
  To: ltp

Fixed by:
commit 38327424b40bcebe2de92d07312c89360ac9229a
Author: Dan Carpenter <dan.carpenter@oracle.com>
Date:   Thu Jun 16 15:48:57 2016 +0100

    KEYS: potential uninitialized variable

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
 runtest/commands                      |  1 +
 testcases/commands/keyctl/Makefile    | 24 ++++++++++
 testcases/commands/keyctl/keyctl01.sh | 89 +++++++++++++++++++++++++++++++++++
 3 files changed, 114 insertions(+)
 create mode 100644 testcases/commands/keyctl/Makefile
 create mode 100644 testcases/commands/keyctl/keyctl01.sh

diff --git a/runtest/commands b/runtest/commands
index fd51703..682deda 100644
--- a/runtest/commands
+++ b/runtest/commands
@@ -41,3 +41,4 @@ which01 which01.sh
 lsmod01 lsmod01.sh
 insmod01 insmod01.sh
 wc01 wc01.sh
+keyctl01 keyctl01.sh
diff --git a/testcases/commands/keyctl/Makefile b/testcases/commands/keyctl/Makefile
new file mode 100644
index 0000000..144beed
--- /dev/null
+++ b/testcases/commands/keyctl/Makefile
@@ -0,0 +1,24 @@
+#
+#    commands/keyctl testcases Makefile.
+#
+#    Copyright (c) 2017 Fujitsu Ltd.
+#    Author:Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+
+top_srcdir		?= ../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_TARGETS		:= keyctl01.sh
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/commands/keyctl/keyctl01.sh b/testcases/commands/keyctl/keyctl01.sh
new file mode 100644
index 0000000..076a130
--- /dev/null
+++ b/testcases/commands/keyctl/keyctl01.sh
@@ -0,0 +1,89 @@
+#!/bin/sh
+#
+# Copyright (c) 2017 Fujitsu Ltd.
+# Ported: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program, if not, see <http://www.gnu.org/licenses/>.
+#
+# This is a regression test about potential uninitialized variable,
+# the test can crash the buggy kernel, and the bug has been fixed in:
+#
+#   commit 38327424b40bcebe2de92d07312c89360ac9229a
+#   Author: Dan Carpenter <dan.carpenter@oracle.com>
+#   Date:   Thu Jun 16 15:48:57 2016 +0100
+#
+#   KEYS: potential uninitialized variable
+#
+
+TST_ID="keyctl01"
+TST_SETUP=setup
+TST_CLEANUP=cleanup
+TST_TESTFUNC=do_test
+TST_NEEDS_ROOT=1
+TST_NEEDS_TMPDIR=1
+TST_NEEDS_CMDS="keyctl"
+. tst_test.sh
+
+setup()
+{
+	if tst_kvcmp -le 2.6.33; then
+		tst_brk TCONF "Kernel newer than 2.6.33 is needed"
+	fi
+
+	PATH_KEYSTAT="/proc/key-users"
+	PATH_KEYQUOTA="/proc/sys/kernel/keys/root_maxbytes"
+
+	if [ ! -f "$PATH_KEYSTAT" ] || [ ! -f "$PATH_KEYQUOTA" ]; then
+		tst_brk TCONF "'${PATH_KEYSTAT}' or '${PATH_KEYQUOTA}' \
+			does not exist"
+	fi
+
+	ORIG_KEYSZ=`awk -F' +|/' '/ 0:/ {print $8}' $PATH_KEYSTAT`
+	ORIG_MAXKEYSZ=`cat $PATH_KEYQUOTA`
+}
+
+cleanup()
+{
+	if [ -n "$ORIG_MAXKEYSZ" ]; then
+		echo $ORIG_MAXKEYSZ >$PATH_KEYQUOTA
+	fi
+}
+
+do_test()
+{
+	local maxkeysz=$((ORIG_KEYSZ + 100))
+
+	while true
+	do
+		echo $maxkeysz >$PATH_KEYQUOTA
+
+		keyctl request2 user debug:fred negate @t >temp 2>&1
+		grep -q -E "quota exceeded" temp
+		if [ $? -eq 0 ]; then
+			break
+		fi
+
+		local key=`keyctl show | awk '/debug:fred/ {print $1}'`
+		if [ -n "$key" ]; then
+			keyctl unlink $key @s >/dev/null
+			tst_sleep 50ms
+		fi
+
+		((maxkeysz -= 4))
+	done
+
+	tst_res TPASS "Bug not reproduced"
+}
+
+tst_run
-- 
1.8.4.2




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v2] commands/keyctl01: Add new regression test
  2017-03-29  2:09         ` [LTP] [PATCH v2] " Guangwen Feng
@ 2017-03-29 16:53           ` Cyril Hrubis
  0 siblings, 0 replies; 7+ messages in thread
From: Cyril Hrubis @ 2017-03-29 16:53 UTC (permalink / raw)
  To: ltp

Hi!
Pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-03-29 16:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-15 11:13 [LTP] [PATCH] commands/keyctl01: Add new regression test Guangwen Feng
2017-03-27 13:42 ` Cyril Hrubis
2017-03-28  6:46   ` Guangwen Feng
2017-03-28  8:34     ` Cyril Hrubis
2017-03-28 10:37       ` Guangwen Feng
2017-03-29  2:09         ` [LTP] [PATCH v2] " Guangwen Feng
2017-03-29 16:53           ` Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.