2010-04-19 13:57:56

by Jan Engelhardt

[permalink] [raw]
Subject: [patch] vt: deactive Shift In/Out in unicode mode

Hi,



I am proposing the patch below for inclusion.
Also pullable via
git://dev.medozas.de/linux siso

##
parent d93af0ec5842904b701927b0b4da41e59f284e45 (v2.6.34-rc1-1127-gd93af0e)
commit 063c73c9d7c4e7a86e99c9e7eefc2b47a9262065
Author: Jan Engelhardt <[email protected]>
Date: Sat Apr 10 12:40:31 2010 +0200

vt: deactive Shift In/Out in unicode mode

WP describes these control codes as: "The original meaning of those
characters was to switch to a different character set and back. This
was used, for instance, in the Russian character set known as KOI7,
where SO starts printing Russian letters, and SI starts printing Latin
letters again."

It is easy to switch one's terminal into gibberish mode by merely
cat-ing a file which has these characters (may happen with corrupted
text files, or if accidentally displaying the contents of a binary
file). This patch deactivates the processing of the control chars in
Unicode mode, where this switch is not needed.

Signed-off-by: Jan Engelhardt <[email protected]>
---
drivers/char/vt.c | 16 ++++++----
net/netfilter/xt_condition.c | 53 +++++++++++++--------------------
2 files changed, 31 insertions(+), 38 deletions(-)

diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index bd1d116..a3e66bc 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -1698,14 +1698,18 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c)
cr(vc);
return;
case 14:
- vc->vc_charset = 1;
- vc->vc_translate = set_translate(vc->vc_G1_charset, vc);
- vc->vc_disp_ctrl = 1;
+ if (!vc->vc_utf) {
+ vc->vc_charset = 1;
+ vc->vc_translate = set_translate(vc->vc_G1_charset, vc);
+ vc->vc_disp_ctrl = 1;
+ }
return;
case 15:
- vc->vc_charset = 0;
- vc->vc_translate = set_translate(vc->vc_G0_charset, vc);
- vc->vc_disp_ctrl = 0;
+ if (!vc->vc_utf) {
+ vc->vc_charset = 0;
+ vc->vc_translate = set_translate(vc->vc_G0_charset, vc);
+ vc->vc_disp_ctrl = 0;
+ }
return;
case 24: case 26:
vc->vc_state = ESnormal;
diff --git a/net/netfilter/xt_condition.c b/net/netfilter/xt_condition.c
index d3dcaa4..6594338 100644
--- a/net/netfilter/xt_condition.c
+++ b/net/netfilter/xt_condition.c
@@ -52,7 +52,7 @@ struct condition_variable {

/* proc_lock is a user context only semaphore used for write access */
/* to the conditions' list. */
-static struct mutex proc_lock;
+static DEFINE_MUTEX(proc_lock);

static LIST_HEAD(conditions_list);
static struct proc_dir_entry *proc_net_condition;
@@ -96,13 +96,8 @@ condition_mt(const struct sk_buff *skb, const struct xt_match_param *par)
{
const struct xt_condition_mtinfo *info = par->matchinfo;
const struct condition_variable *var = info->condvar;
- bool x;

- rcu_read_lock();
- x = rcu_dereference(var->enabled);
- rcu_read_unlock();
-
- return x ^ info->invert;
+ return var->enabled ^ info->invert;
}

static int condition_mt_check(const struct xt_mtchk_param *par)
@@ -122,9 +117,7 @@ static int condition_mt_check(const struct xt_mtchk_param *par)
* Let's acquire the lock, check for the condition and add it
* or increase the reference counter.
*/
- if (mutex_lock_interruptible(&proc_lock) != 0)
- return -EINTR;
-
+ mutex_lock(&proc_lock);
list_for_each_entry(var, &conditions_list, list) {
if (strcmp(info->name, var->status_proc->name) == 0) {
++var->refcount;
@@ -156,7 +149,7 @@ static int condition_mt_check(const struct xt_mtchk_param *par)
wmb();
var->status_proc->read_proc = condition_proc_read;
var->status_proc->write_proc = condition_proc_write;
- list_add_rcu(&var->list, &conditions_list);
+ list_add(&var->list, &conditions_list);
var->status_proc->uid = condition_uid_perms;
var->status_proc->gid = condition_gid_perms;
mutex_unlock(&proc_lock);
@@ -171,16 +164,9 @@ static void condition_mt_destroy(const struct xt_mtdtor_param *par)

mutex_lock(&proc_lock);
if (--var->refcount == 0) {
- list_del_rcu(&var->list);
+ list_del(&var->list);
remove_proc_entry(var->status_proc->name, proc_net_condition);
mutex_unlock(&proc_lock);
- /*
- * synchronize_rcu() would be good enough, but
- * synchronize_net() guarantees that no packet
- * will go out with the old rule after
- * succesful removal.
- */
- synchronize_net();
kfree(var);
return;
}
@@ -202,24 +188,13 @@ static const char *const dir_name = "nf_condition";

static int __net_init condnet_mt_init(struct net *net)
{
- int ret;
-
proc_net_condition = proc_mkdir(dir_name, net->proc_net);
- if (proc_net_condition == NULL)
- return -EACCES;
-
- ret = xt_register_match(&condition_mt_reg);
- if (ret < 0) {
- remove_proc_entry(dir_name, net->proc_net);
- return ret;
- }

- return 0;
+ return (proc_net_condition == NULL) ? -EACCES : 0;
}

static void __net_exit condnet_mt_exit(struct net *net)
{
- xt_unregister_match(&condition_mt_reg);
remove_proc_entry(dir_name, net->proc_net);
}

@@ -230,12 +205,26 @@ static struct pernet_operations condition_mt_netops = {

static int __init condition_mt_init(void)
{
+ int ret;
+
mutex_init(&proc_lock);
- return register_pernet_subsys(&condition_mt_netops);
+
+ ret = xt_register_match(&condition_mt_reg);
+ if (ret < 0)
+ return ret;
+
+ ret = register_pernet_subsys(&condition_mt_netops);
+ if (ret < 0) {
+ xt_unregister_match(&condition_mt_reg);
+ return ret;
+ }
+
+ return 0;
}

static void __exit condition_mt_exit(void)
{
+ xt_unregister_match(&condition_mt_reg);
unregister_pernet_subsys(&condition_mt_netops);
}

--
# Created with git-export-patch


2010-04-19 14:27:22

by Alan

[permalink] [raw]
Subject: Re: [patch] vt: deactive Shift In/Out in unicode mode

On Mon, 19 Apr 2010 15:57:52 +0200 (CEST)
Jan Engelhardt <[email protected]> wrote:

> Hi,
>
>
>
> I am proposing the patch below for inclusion.
> Also pullable via
> git://dev.medozas.de/linux siso

It seems to do a lot of other things as well. Can you split out just the
relevant bit ?

2010-04-19 14:29:44

by Alexander E. Patrakov

[permalink] [raw]
Subject: Re: [patch] vt: deactive Shift In/Out in unicode mode

Jan Engelhardt wrote:
> vt: deactive Shift In/Out in unicode mode
>
> WP describes these control codes as: "The original meaning of those
> characters was to switch to a different character set and back. This
> was used, for instance, in the Russian character set known as KOI7,
> where SO starts printing Russian letters, and SI starts printing Latin
> letters again."

Since KOI7 is not used by any glibc locale, your use case is now
extinct. I think that, unless someone finds out a different use case,
these SI and SO characters should be deactivated completely (and not
just in unicode mode).

--
Alexander E. Patrakov

2010-04-19 16:20:29

by Jan Engelhardt

[permalink] [raw]
Subject: Re: [patch] vt: deactive Shift In/Out in unicode mode


On Monday 2010-04-19 16:31, Alan Cox wrote:
>>
>> I am proposing the patch below for inclusion.
>> Also pullable via
>> git://dev.medozas.de/linux siso
>
>It seems to do a lot of other things as well. Can you split out just the
>relevant bit ?

It's really just the top commit. Perhaps I should rebase it to a
v2.6.34-rcX tag so that shortlog does what one expects.

Alexander mentioned:

[quoting the gmane nntp posting which was stripped of To:s and Cc:s]
>
>Since KOI7 is not used by any glibc locale, your use case is now
>extinct. I think that, unless someone finds out a different use case,
>these SI and SO characters should be deactivated completely (and not
>just in unicode mode).

Alan, do you agree that the entire SI/SO can/should be removed?

2010-04-20 20:08:38

by James Cloos

[permalink] [raw]
Subject: Re: [patch] vt: deactive Shift In/Out in unicode mode

>>>>> "AEP" == Alexander E Patrakov <[email protected]> writes:

AEP> Since KOI7 is not used by any glibc locale, your use case is now
AEP> extinct. I think that, unless someone finds out a different use case,
AEP> these SI and SO characters should be deactivated completely (and not
AEP> just in unicode mode).

SI/SO is also relevant for line draw characters and the like.

Here is a key for the default set in my (X11) term emulator,
I presume it is the same as what the console supports:

_ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~
▮ ◆ ▒ ␉ ␌ ␍ ␊ ° ± ␤ ␋ ┘ ┐ ┌ └ ┼ ⎺ ⎻ ─ ⎼ ⎽ ├ ┤ ┴ ┬ │ ≤ ≥ π ≠ £ ·

Those are important, and the console should continue to support them
even when not in UTF-8 mode.

-JimC
--
James Cloos <[email protected]> OpenPGP: 1024D/ED7DAEA6

2010-04-20 23:52:57

by H. Peter Anvin

[permalink] [raw]
Subject: Re: [patch] vt: deactive Shift In/Out in unicode mode

On 04/19/2010 09:20 AM, Jan Engelhardt wrote:
>
> On Monday 2010-04-19 16:31, Alan Cox wrote:
>>>
>>> I am proposing the patch below for inclusion.
>>> Also pullable via
>>> git://dev.medozas.de/linux siso
>>
>> It seems to do a lot of other things as well. Can you split out just the
>> relevant bit ?
>
> It's really just the top commit. Perhaps I should rebase it to a
> v2.6.34-rcX tag so that shortlog does what one expects.
>
> Alexander mentioned:
>
> [quoting the gmane nntp posting which was stripped of To:s and Cc:s]
>>
>> Since KOI7 is not used by any glibc locale, your use case is now
>> extinct. I think that, unless someone finds out a different use case,
>> these SI and SO characters should be deactivated completely (and not
>> just in unicode mode).
>
> Alan, do you agree that the entire SI/SO can/should be removed?

VT line drawing characters are generally assumed to be accessible using
SI/SO (as they are by default.)

-hpa

2010-04-22 08:39:33

by Jan Engelhardt

[permalink] [raw]
Subject: Re: [patch] vt: deactive Shift In/Out in unicode mode


On Wednesday 2010-04-21 01:49, H. Peter Anvin wrote:
>> Alexander mentioned:
>> [quoting the gmane nntp posting which was stripped of To:s and Cc:s]
>>>
>>> Since KOI7 is not used by any glibc locale, your use case is now
>>> extinct. I think that, unless someone finds out a different use case,
>>> these SI and SO characters should be deactivated completely (and not
>>> just in unicode mode).
>>
>> Alan, do you agree that the entire SI/SO can/should be removed?
>
>VT line drawing characters are generally assumed to be accessible using
>SI/SO (as they are by default.)

Indeed 0x0e 0x71 0x0f generates the same output as U+2501.

I can't say when the last time was that I saw SISO in use, though.
At least UTF-8 programs just print U+2501, so it should
be fine to exclude SISO handling there.
With

echo -en "\e%@"; setfont r -u /usr/share/kbd/unimaps/cp437.uni;
LC_CTYPE=C mc

it would also output no SISO and use 0xc4 for U+2501.

2010-04-22 13:30:33

by H. Peter Anvin

[permalink] [raw]
Subject: Re: [patch] vt: deactive Shift In/Out in unicode mode

On 04/22/2010 01:39 AM, Jan Engelhardt wrote:
>
> Indeed 0x0e 0x71 0x0f generates the same output as U+2501.
>
> I can't say when the last time was that I saw SISO in use, though.

Probably a lot more recently than you think, especially if you are
dealing with terminal input from other hosts.

-hpa

--
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel. I don't speak on their behalf.