From: Chen Gang <hidden> Date: 2012-11-29 05:57:10
于 2012年11月29日 13:13, Greg KH 写道:
On Thu, Nov 29, 2012 at 12:40:49PM +0800, Chen Gang wrote:
quoted
Hello Greg Kroah-Hartman:
for MAX_ASYNC_BUFFER_SIZE:
it is defined as 4096;
but for the max buffer size which it processes, is 65535.
so suggest to #define MAX_ASYNC_BUFFER_SIZE 0x10000 (better than 0xffff)
Please, send tty questions to the linux-serial@vger.kernel.org list
also.
I cc to linux-serial@vger.kernel.org, in this reply.
I referenced the file MAINTAINERS, before sent original mail:
it seems all drivers/tty/serial/* are relative with
linux-serial@vger.kernel.org. but our case is not relative
drivers/tty/serial. so for not bother them, I am not send to them,
originally.
in MAINTAINERS, line 7438, I find for common of driver/tty/*, can send
to you and no cc, so I send you and cc to linux-kernel@vger.kernel.org.
next time, for all tty questions, I will cc to
linux-serial@vger.kernel.org (not cc to linux-kernel@vger.kernel.org).
And, I really don't understand here, why do you want to change this?
What is it going to change? And why?
Why:
for the context MGSLPC_INFO *info in drivers/char/pcmcia/synclink_cs.c
info->max_frame_size can be the value between 4096 .. 65535 (can be
set by its module input parameter)
info->flag_buf length is 4096 (MAX_ASYNC_BUFFER_SIZE)
in function rx_get_frame
the framesize is limit by info->max_frame_size, but may still be
larger that 4096.
when call function ldisc_receive_buf, info->flag_buf is equal to
4096, but framesize can be more than 4096. it will cause memory over flow.
What:
#define MAX_ASYNC_BUFFER_SIZE 0x10000 (instead of 4096, originally).
let it match the max frame size.
At last:
my suggestion may be incorrect, need relative member (who expert about
it) to help checking.
welcome another suggestion or completions.
thanks.
gchen.
thank you very much.
--
Chen Gang
Asianux Corporation
--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, Nov 29, 2012 at 01:57:59PM +0800, Chen Gang wrote:
quoted
And, I really don't understand here, why do you want to change this?
What is it going to change? And why?
Why:
for the context MGSLPC_INFO *info in drivers/char/pcmcia/synclink_cs.c
info->max_frame_size can be the value between 4096 .. 65535 (can be
set by its module input parameter)
info->flag_buf length is 4096 (MAX_ASYNC_BUFFER_SIZE)
in function rx_get_frame
the framesize is limit by info->max_frame_size, but may still be
larger that 4096.
when call function ldisc_receive_buf, info->flag_buf is equal to
4096, but framesize can be more than 4096. it will cause memory over flow.
Do you use that pcmcia driver for anything? Are those cards still
around?
What:
#define MAX_ASYNC_BUFFER_SIZE 0x10000 (instead of 4096, originally).
let it match the max frame size.
At last:
my suggestion may be incorrect, need relative member (who expert about
it) to help checking.
That driver might be incorrect, yes, care to make up a patch for it and
test it to verify it fixes the problem?
thanks,
greg k-h
From: Chen Gang <hidden> Date: 2012-11-30 02:51:49
于 2012年11月30日 02:32, Greg KH 写道:
On Thu, Nov 29, 2012 at 01:57:59PM +0800, Chen Gang wrote:
quoted
quoted
And, I really don't understand here, why do you want to change this?
What is it going to change? And why?
Why:
for the context MGSLPC_INFO *info in drivers/char/pcmcia/synclink_cs.c
info->max_frame_size can be the value between 4096 .. 65535 (can be
set by its module input parameter)
info->flag_buf length is 4096 (MAX_ASYNC_BUFFER_SIZE)
in function rx_get_frame
the framesize is limit by info->max_frame_size, but may still be
larger that 4096.
when call function ldisc_receive_buf, info->flag_buf is equal to
4096, but framesize can be more than 4096. it will cause memory over flow.
Do you use that pcmcia driver for anything? Are those cards still
around?
I am not use them.
I am just through code review (so it is only a suggestion).
this issue has effect with 4 synclink drivers
I checked their source code, all of them have the same issue.
drivers/char/pcmcia/synclink_cs.c:213: char flag_buf[MAX_ASYNC_BUFFER_SIZE];
drivers/tty/synclink_gt.c:320: char flag_buf[MAX_ASYNC_BUFFER_SIZE];
drivers/tty/synclink.c:294: char flag_buf[MAX_ASYNC_BUFFER_SIZE];
drivers/tty/synclinkmp.c:265: char flag_buf[MAX_ASYNC_BUFFER_SIZE];
by the way, for the char_buf, has already useless (can be removed)
drivers/tty/synclink_gt.c:321: char char_buf[MAX_ASYNC_BUFFER_SIZE];
drivers/tty/synclink.c:295: char char_buf[MAX_ASYNC_BUFFER_SIZE];
drivers/tty/synclinkmp.c:266: char char_buf[MAX_ASYNC_BUFFER_SIZE];
quoted
What:
#define MAX_ASYNC_BUFFER_SIZE 0x10000 (instead of 4096, originally).
let it match the max frame size.
At last:
my suggestion may be incorrect, need relative member (who expert about
it) to help checking.
That driver might be incorrect, yes, care to make up a patch for it and
test it to verify it fixes the problem?
and now Alan Cox has his own opinions
at least, I think it is valuable to continue discussing about it.
if Alan Cox agree with it (but it seems not), I will make patch, and try to perform test.
also welcome another members to help testing.
thanks,
greg k-h
--
Chen Gang
Asianux Corporation
--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Paul Fulghum <hidden> Date: 2012-11-30 16:24:12
On 11/29/2012 8:52 PM, Chen Gang wrote:
于 2012年11月30日 02:32, Greg KH 写道:
quoted
On Thu, Nov 29, 2012 at 01:57:59PM +0800, Chen Gang wrote:
quoted
quoted
And, I really don't understand here, why do you want to change this?
What is it going to change? And why?
Why:
for the context MGSLPC_INFO *info in drivers/char/pcmcia/synclink_cs.c
info->max_frame_size can be the value between 4096 .. 65535 (can be
set by its module input parameter)
info->flag_buf length is 4096 (MAX_ASYNC_BUFFER_SIZE)
in function rx_get_frame
the framesize is limit by info->max_frame_size, but may still be
larger that 4096.
when call function ldisc_receive_buf, info->flag_buf is equal to
4096, but framesize can be more than 4096. it will cause memory over flow.
The confusion centers on calling the line discipline receive_buf
function with a data buffer larger than the flag buffer.
The synclink drivers support asynchronous and synchronous (HDLC)
serial communications.
In asynchronous mode, the tty flip buffer is used to feed
data to the line discipline. In this mode, the above argument
does not apply. The receive_buf function is not called directly.
In synchronous mode, the driver calls the line discipline
receive_buf function directly to feed one HDLC frame
of data per call. Maintaining frame boundaries is needed
in this mode. This is done only with the N_HDLC line
discipline which expects this format and ignores the flag buffer.
The flag buffer passed is just a place holder to meet the
calling conventions of the line discipline receive_buf function.
The only danger is if:
1. driver is configured for synchronous mode
2. driver is configured for frames > 4K
3. line discipline other than N_HDLC is selected
In this case the line discipline might try to access
beyond the end of the flag buffer. This is a non-functional
configuration that would not occur on purpose.
Increasing the flag buffer size would prevent a problem
in this degenerate case of purposeful misconfiguration.
This would be at the expense of larger allocations that are
not used.
I think the correct fix is for me to change the direct
calls to pass the same buffer for both data and flag and
add a comment describing the fact the flag buffer is ignored
when using N_HDLC. That way a misconfigured setup won't
cause problems and no unneeded allocations are made.
My suggestion is to leave it as is for now until I can make
those changes. I admit the current code is ugly enough to
cause confusion (sorry Chen Gang), but I don't see any immediate danger.
--
Paul Fulghum
MicroGate Systems, Ltd.
=Customer Driven, by Design=
(800)444-1982 (US Sales)
(512)345-7791 x102 (Direct)
(512)343-9046 (Fax)
Central Time Zone (GMT -6h)
www.microgate.com
From: Paul Fulghum <hidden> Date: 2012-11-30 19:46:22
Fix call to line discipline receive_buf by synclink drivers.
Dummy flag buffer argument is ignored by N_HDLC line discipline but might
be of insufficient size if accessed by a different line discipline
selected by mistake. Calls are changed to use data buffer argument for
both data and flag buffer so valid memory is provided if the wrong
line discipline is used. Unused char_buf and flag_buf are removed.
Signed-off-by: Paul Fulghum <redacted>
@@ -6661,7 +6659,17 @@ static bool mgsl_get_rx_frame(struct mgshdlcdev_rx(info,info->intermediate_rxbuffer,framesize);else#endif-ldisc_receive_buf(tty,info->intermediate_rxbuffer,info->flag_buf,framesize);+{+/*+*CallN_HDLClinedisciplinedirectlytomaintain+*frameboundaries.Reusethedatabufferargumentforthe+*flagbufferargument.TheflagbufferisignoredbyN_HDLC.+*Ifadifferentlinedisciplineisselectedbymistakeit+*willhavevalidmemoryforbotharguments.+*/+ldisc_receive_buf(tty,info->intermediate_rxbuffer,+info->intermediate_rxbuffer,framesize);+}}}/* Free the buffers used by this frame. */
@@ -6833,7 +6841,15 @@ static bool mgsl_get_raw_rx_frame(structmemcpy(info->intermediate_rxbuffer,pBufEntry->virt_addr,framesize);info->icount.rxok++;-ldisc_receive_buf(tty,info->intermediate_rxbuffer,info->flag_buf,framesize);+/*+*CallN_HDLClinedisciplinedirectlytomaintain+*blockboundaries.Reusethedatabufferargumentforthe+*flagbufferargument.TheflagbufferisignoredbyN_HDLC.+*Ifadifferentlinedisciplineisselectedbymistakeit+*willhavevalidmemoryforbotharguments.+*/+ldisc_receive_buf(tty,info->intermediate_rxbuffer,+info->intermediate_rxbuffer,framesize);}/* Free the buffers used by this frame. */---a/drivers/tty/synclinkmp.c2012-11-2614:15:45.000000000-0600+++b/drivers/tty/synclinkmp.c2012-11-3013:01:36.000000000-0600
@@ -4979,8 +4977,17 @@ CheckAgain:hdlcdev_rx(info,info->tmp_rx_buf,framesize);else#endif-ldisc_receive_buf(tty,info->tmp_rx_buf,-info->flag_buf,framesize);+{+/*+*CallN_HDLClinedisciplinedirectlytomaintain+*frameboundaries.Reusethedatabufferargumentforthe+*flagbufferargument.TheflagbufferisignoredbyN_HDLC.+*Ifadifferentlinedisciplineisselectedbymistakeit+*willhavevalidmemoryforbotharguments.+*/+ldisc_receive_buf(tty,info->tmp_rx_buf,+info->tmp_rx_buf,framesize);+}}}/* Free the buffers used by this frame. */---a/drivers/tty/synclink_gt.c2012-11-2614:15:45.000000000-0600+++b/drivers/tty/synclink_gt.c2012-11-3012:53:25.000000000-0600
From: Chen Gang <hidden> Date: 2012-12-01 09:00:15
于 2012年12月01日 00:24, Paul Fulghum 写道:
My suggestion is to leave it as is for now until I can make
those changes. I admit the current code is ugly enough to
cause confusion (sorry Chen Gang), but I don't see any immediate danger.
do not need 'sorry', learn with each other. (I am just learning
through read kernel source code -- "code review")
I am glad to know that my suggestion is useful (although it seems a
minor suggestion). for me, it is enough.
:-)
thanks.
--
Chen Gang
Asianux Corporation
--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
+ * If a different line discipline is selected by mistake it
+ * will have valid memory for both arguments.
+ */
+ ldisc_receive_buf(tty, buf->data, buf->data, framesize);
From: Paul Fulghum <hidden> Date: 2012-12-03 17:13:13
Fix call to line discipline receive_buf by synclink drivers.
Dummy flag buffer argument is ignored by N_HDLC line discipline but might
be of insufficient size if accessed by a different line discipline
selected by mistake. flag buffer allocation now matches max size of data
buffer. Unused char_buf buffers are removed.
Signed-off-by: Paul Fulghum <redacted>
@@ -3891,7 +3890,13 @@ static int mgsl_alloc_intermediate_rxbufinfo->intermediate_rxbuffer=kmalloc(info->max_frame_size,GFP_KERNEL|GFP_DMA);if(info->intermediate_rxbuffer==NULL)return-ENOMEM;-+/* unused flag buffer to satisfy receive_buf calling interface */+info->flag_buf=kzalloc(info->max_frame_size,GFP_KERNEL);+if(!info->flag_buf){+kfree(info->intermediate_rxbuffer);+info->intermediate_rxbuffer=NULL;+return-ENOMEM;+}return0;}/* end of mgsl_alloc_intermediate_rxbuffer_memory() */
@@ -3910,6 +3915,8 @@ static void mgsl_free_intermediate_rxbuf{kfree(info->intermediate_rxbuffer);info->intermediate_rxbuffer=NULL;+kfree(info->flag_buf);+info->flag_buf=NULL;}/* end of mgsl_free_intermediate_rxbuffer_memory() */---a/drivers/tty/synclinkmp.c2012-11-2614:15:45.000000000-0600+++b/drivers/tty/synclinkmp.c2012-12-0310:52:09.000000000-0600
From: Chen Gang <hidden> Date: 2012-12-05 01:34:21
于 2012年12月04日 01:13, Paul Fulghum 写道:
Fix call to line discipline receive_buf by synclink drivers.
Dummy flag buffer argument is ignored by N_HDLC line discipline but might
be of insufficient size if accessed by a different line discipline
selected by mistake. flag buffer allocation now matches max size of data
buffer. Unused char_buf buffers are removed.
Signed-off-by: Paul Fulghum <redacted>
thank you very much.
might we use macro instead of hard code number ? (such as 4096,
65535). it is only an idea, not means need regression.
thanks.
--
Chen Gang
Asianux Corporation
--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Chen Gang <hidden> Date: 2012-12-07 02:14:31
Hello Greg Kroah-Hartman:
于 2012年12月04日 01:13, Paul Fulghum 写道:
Fix call to line discipline receive_buf by synclink drivers.
Dummy flag buffer argument is ignored by N_HDLC line discipline but might
be of insufficient size if accessed by a different line discipline
selected by mistake. flag buffer allocation now matches max size of data
buffer. Unused char_buf buffers are removed.
Signed-off-by: Paul Fulghum <redacted>
if no additional questions:
is it suitable to let this patch pass checking ?
at least for me, it is surely solve an issue, and no negative effect.
now, maybe Paul Fulghum is busy...
the left questions what I have sent seems minor.
so they can be delayed, until he has free time.
when Paul Fulghum has free time.
can still check what my left questions whether valid.
if they are valid, can send additional patch for them.
is it OK ?
Regards
--
Chen Gang
Asianux Corporation
--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Chen Gang <hidden> Date: 2012-12-10 01:31:33
Hello Paul Fulghum:
Firstly, sorry for my mistake:
I am a reporter (not reviewer), and not suitable to review maintainer's patch.
when you send relative patch, need not cc to me (I am not reviewer)
so:
could you send patch again (not need cc to me) ?
(and also it is better to mark me as Reported-by in your patch)
sorry for my mistake, again.
gchen.
于 2012年12月07日 10:15, Chen Gang 写道:
Hello Greg Kroah-Hartman:
于 2012年12月04日 01:13, Paul Fulghum 写道:
quoted
Fix call to line discipline receive_buf by synclink drivers.
Dummy flag buffer argument is ignored by N_HDLC line discipline but might
be of insufficient size if accessed by a different line discipline
selected by mistake. flag buffer allocation now matches max size of data
buffer. Unused char_buf buffers are removed.
Signed-off-by: Paul Fulghum <redacted>
if no additional questions:
is it suitable to let this patch pass checking ?
at least for me, it is surely solve an issue, and no negative effect.
now, maybe Paul Fulghum is busy...
the left questions what I have sent seems minor.
so they can be delayed, until he has free time.
when Paul Fulghum has free time.
can still check what my left questions whether valid.
if they are valid, can send additional patch for them.
is it OK ?
Regards
--
Chen Gang
Asianux Corporation
--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html